#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    30
    Rep Power
    2

    PHP header function not setting setcookie header


    Hello all,

    I am trying to set set-cookie header using header function in php

    This is the header I am trying to set

    Set-Cookie: A1=""; Expires=Thu, 01-Dec-94 16:00:00 GMT; Path=/

    But this function is not able to set this header , please note the value of cookie is "" ( null )..

    Also I am able to set other set-cookie headers where value of cookie is not null..

    Anybody have an idea what can be the issue..

    Amit.
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,112
    Rep Power
    9398
    So you're trying to delete a cookie?

    What's your code?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    30
    Rep Power
    2
    Originally Posted by requinix
    So you're trying to delete a cookie?

    What's your code?
    Yes .. actually , using php .. i am just proxy ing the request , I am just trying to send the headers to browser which i am getting from real server .. I am acting (my php code) as proxy , so real server is trying to delete the cookies by sending empty cookies .. php code receive them as heades ( Set-Cookie: k1=""; Expires=Thu, 01-Dec-94 16:00:00 GMT; Path=/; ) and php code is just trying to set this header to browser.. My problem is when i user header function to send the header , it is not able to set cookie in browser. ( set empty cookie)

    This is what i try to do ,

    // Get headers from the results i received from real server
    $headerArray = explode("\r\n", $response[header]);

    // Set headers for browser
    foreach($headerArray as $headerLine) {
    header($headerLine);
    error_log("Route.php ... Headers Received .... $headerLine ");

    }
  6. #4
  7. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,112
    Rep Power
    9398
    Is your PHP executing on the adp.com domain? Can't set a cookie for a different domain...

    ADP, huh? What's this proxying for?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    30
    Rep Power
    2
    Originally Posted by requinix
    Is your PHP executing on the adp.com domain? Can't set a cookie for a different domain...

    ADP, huh? What's this proxying for?
    yes

    here is the scenario

    Browser - > PHP Code - > Server

    Request lands on PHP , php connects with server , send whole request , server respond back to php with set-cookie headers , php needs to send those header back to browser , it is doing fine for all other headers but when value is "" , it is not setting those set-cookie headers
  10. #6
  11. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    You know there's an actual setcookie function in PHP right?
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    30
    Rep Power
    2
    Originally Posted by ManiacDan
    You know there's an actual setcookie function in PHP right?
    yes i know , but i dont want to parse the headers and set them in cookies .. i just want to pass the information along
  14. #8
  15. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    The cookies are domain specific, and you're from the wrong domain.

    You should be using something like SnoopyPHP for this, since you're making a proxy.

    Or just use an existing proxy product.

    Or...anything but writing this as a PHP pass-through.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    30
    Rep Power
    2
    Originally Posted by ManiacDan
    The cookies are domain specific, and you're from the wrong domain.

    You should be using something like SnoopyPHP for this, since you're making a proxy.

    Or just use an existing proxy product.

    Or...anything but writing this as a PHP pass-through.
    Hi ManiacDan..

    I am setting cookie in right domain.. I am able to set other cookies , only problem i have is when cookie value is ""
  18. #10
  19. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,112
    Rep Power
    9398
    Can you confirm the client is receiving the right header? You're just forwarding the headers so the user should be getting what the server is sending, and that means if it's not working with the proxy then it shouldn't work without too.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    30
    Rep Power
    2
    Originally Posted by requinix
    Can you confirm the client is receiving the right header? You're just forwarding the headers so the user should be getting what the server is sending, and that means if it's not working with the proxy then it shouldn't work without too.
    It is *not* working with the proxy .. client is able to receive it when it is directly sent by server.. when php code comes in .. it stop
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    30
    Rep Power
    2
    Originally Posted by amitvce
    It is *not* working with the proxy .. client is able to receive it when it is directly sent by server.. when php code comes in .. it stop

    in fact just now i tried with setcookie.. It is also not working .. the cookie is not getting set in browser.

    setcookie("A1","",time()-3600,"/",".....
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    30
    Rep Power
    2
    Originally Posted by amitvce
    in fact just now i tried with setcookie.. It is also not working .. the cookie is not getting set in browser.

    setcookie("A1","",time()-3600,"/",".....
    Guys the issue is resolved , when i was setting the headers.. by default header function was not taking duplicate headers , so one set-cookie was replaced by other one and only one was getting to browser .. I tweaked the function to take multiple similar headers ..
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,996
    Rep Power
    375
    thanks for letting us know and posting the solution.

    having said that, if you had posted the right info/code then perhaps people would have spotted that error straight away
  28. #15
  29. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,112
    Rep Power
    9398
    Originally Posted by paulh1983
    having said that, if you had posted the right info/code then perhaps people would have spotted that error straight away
    He did, in the third post. I, for one, hadn't considered that there might be multiple instances of a header - it doesn't happen that often.

IMN logo majestic logo threadwatch logo seochat tools logo