Jump to content

Recommended Posts

test.php

<?php
setcookie("test", 'tester', time()+3600*24*30 , "/", ".mystagingsite1.com");
header('Location: test2.php');
?>

test2.php

<?php
echo '<pre>';
print_r($_COOKIE);
echo '</pre>';
?>

 

This does not work. It's not setting the cookie at all.  Is there something I am doing wrong here?

Link to comment
https://forums.phpfreaks.com/topic/212963-cookie-wont-save/
Share on other sites

Another question. I just found out it is available under $_REQUEST but not $_COOKIE that is strange. Is there a reason it's working like that?  Am I doing something wrong in setting it?

 

However, request even only works in a test environment. When I try to put this into a script as just basic it's not saving the session data. Is there something I am doing wrong?

Link to comment
https://forums.phpfreaks.com/topic/212963-cookie-wont-save/#findComment-1109185
Share on other sites

I am testing this entire thing on a production server. I am confused as to why it's not working though, because I have done this before many times with no issues.  If I do the basic test I can access it using $_REQUEST even after browser close, but not in $_COOKIE.  Also when I have it in the actual login script and set 2-3 cookies none of them are saving for some reason. I have never had this kind of issue before.

Link to comment
https://forums.phpfreaks.com/topic/212963-cookie-wont-save/#findComment-1109190
Share on other sites

I am not sure what you mean?  The only thing I gather from what your saying is I would need to replace the ".mystagingsite1.net to "www.mystagingsite1.net" but I tried

that and it doesn't work either.  Also, according to the documentations the . acts like a wildcard when setting the cookie.  So it's the base domain.

 

So using ".mystagingsite1.net" should work whether the website domain is www.mystagingsite1.net or mystagingsite1.net.  It's even recommended to show it without the

www at the start.  Is that what you meant?  Either way it doesn't work, as that was one of the first things I tried.

Link to comment
https://forums.phpfreaks.com/topic/212963-cookie-wont-save/#findComment-1109200
Share on other sites

hehe, I understand what you mean now. It would help a lot if I set the .com to .net instead, I am guessing that was an issue there.  :)

 

OK, so that got the basic cookie working.  So now at least I have verified that the cookies are working on my server.  However, there is still something strange when I try to set them in a live environment (meaning in the actual working code.  However, I just went back and retested and it seems there working now.  So it must have been that issue.  There might have been some other issues with how I was doing the time. It seems to all be working now, thanks again.

Link to comment
https://forums.phpfreaks.com/topic/212963-cookie-wont-save/#findComment-1109201
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.