Cookie does not set

前端 未结 4 748
Happy的楠姐
Happy的楠姐 2021-01-21 23:16

I have a cookie that will not set on the remote server, works find locally. No error messages, var_dump gets me Null, echo is blank.



        
相关标签:
4条回答
  • 2021-01-22 00:01

    It could be because you don't specify a path and/or a domain for the cookie. Try this instead:

    <?php
        setcookie('ymp','14', time()+3600, '/', 'yourdomain.com')
    ?>
    
    0 讨论(0)
  • 2021-01-22 00:02

    This problem never did solve, I ended up writing a new file to a different domain on the same host, gave the cookie a different name and value (is it possible that a 3 character name cookie with a 2 digit value too small??) and it worked as supposed expected.

    Thank you all for your help... too busy to do a CSI investigation as to the how's and whys.

    Gary

    0 讨论(0)
  • 2021-01-22 00:05

    You can't read the value of a cookie until a new page request is made. This is because the value of cookie data is sent with the page request. So it isn't available for to access its value until after it is set and a new page request is made.

    Also, session_start() has no effect on cookies. They are two different things. (Sessions do typically use cookies to store the session ID but that is irrelevant).

    0 讨论(0)
  • 2021-01-22 00:09

    This is rather peculiar - I assume this could have something to do with PHP configuration.

    See what the return value of setcookie function is - it may be FALSE if output has been already sent before the function call. You did mention it is right at the start of your script, however there could be other entities outputting data (pre-executed scripts on the server perhaps?)

    It's also possible that your browser is set to not accept cookies from certain domain - check your configuration.

    Please provide any other relevant code and indicate how you check if cookies are set.

    0 讨论(0)
提交回复
热议问题