Ninjakreborn Posted September 9, 2010 Share Posted September 9, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/212963-cookie-wont-save/ Share on other sites More sharing options...
Ninjakreborn Posted September 9, 2010 Author Share Posted September 9, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/212963-cookie-wont-save/#findComment-1109185 Share on other sites More sharing options...
Psycho Posted September 9, 2010 Share Posted September 9, 2010 Are you testing this on a local install or on your production server? Quote Link to comment https://forums.phpfreaks.com/topic/212963-cookie-wont-save/#findComment-1109188 Share on other sites More sharing options...
Ninjakreborn Posted September 9, 2010 Author Share Posted September 9, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/212963-cookie-wont-save/#findComment-1109190 Share on other sites More sharing options...
Psycho Posted September 9, 2010 Share Posted September 9, 2010 Put this in test2.php echo $_SERVER["HTTP_HOST"]; What is output? Quote Link to comment https://forums.phpfreaks.com/topic/212963-cookie-wont-save/#findComment-1109194 Share on other sites More sharing options...
Ninjakreborn Posted September 9, 2010 Author Share Posted September 9, 2010 www.mystagingsite1.net Quote Link to comment https://forums.phpfreaks.com/topic/212963-cookie-wont-save/#findComment-1109195 Share on other sites More sharing options...
Psycho Posted September 9, 2010 Share Posted September 9, 2010 There's your answer - or do you not see the problem? Quote Link to comment https://forums.phpfreaks.com/topic/212963-cookie-wont-save/#findComment-1109199 Share on other sites More sharing options...
Ninjakreborn Posted September 9, 2010 Author Share Posted September 9, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/212963-cookie-wont-save/#findComment-1109200 Share on other sites More sharing options...
Ninjakreborn Posted September 9, 2010 Author Share Posted September 9, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/212963-cookie-wont-save/#findComment-1109201 Share on other sites More sharing options...
Psycho Posted September 9, 2010 Share Posted September 9, 2010 You should consider setting the domain in the cookie dynamically so it will work in any environment and you won't have problems with misspellings and such. Do you even use sub-domains that you need to do that? Quote Link to comment https://forums.phpfreaks.com/topic/212963-cookie-wont-save/#findComment-1109202 Share on other sites More sharing options...
Ninjakreborn Posted September 9, 2010 Author Share Posted September 9, 2010 Hehe, yes I think I will start doing that. I don't use cookies that often, but because of certain client requirements I am having to use them a lot more, so I will probably start doing it a little differently from now on. Quote Link to comment https://forums.phpfreaks.com/topic/212963-cookie-wont-save/#findComment-1109204 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.