trecool999 Posted October 6, 2008 Share Posted October 6, 2008 Hi guys. I have a few years of experience behind me in PHP, MySQL and other languages but there is this one cookie problem I can't get my head around. If you need it, my website is here: http://web-share.org.uk/ Every time I set a cookie, I know it is there because I can check what cookies are set in Firefox. The problem I've been having is that I can't get PHP to recognise it whenever I come back! Every time I visit my site it tells me that no cookie existed, even though I know damn well it has been set because Firefox tells me it has! Please help! If you need the code, I probably won't be able to give it to you as it is set in many different files (It's a template, source, index and functions based website because I'm making a CMS). *UPDATE*: Whenever I click another menu item after closing the browser and opening again, then it tells me there was a cookie... WTF!? Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/ Share on other sites More sharing options...
revraz Posted October 6, 2008 Share Posted October 6, 2008 Is the cookie set with www.web-share.org.uk or just web-share.org.uk? Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/#findComment-658207 Share on other sites More sharing options...
Orio Posted October 6, 2008 Share Posted October 6, 2008 From php.net: Common Pitfalls: [*] Cookies will not become visible until the next loading of a page that the cookie should be visible for. To test if a cookie was successfully set, check for the cookie on a next loading page before the cookie expires. Expire time is set via the expire parameter. A nice way to debug the existence of cookies is by simply calling print_r($_COOKIE);. You're probably checking on the same page you're setting the cookie. Orio. Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/#findComment-658209 Share on other sites More sharing options...
trecool999 Posted October 6, 2008 Author Share Posted October 6, 2008 From php.net: Common Pitfalls: [*] Cookies will not become visible until the next loading of a page that the cookie should be visible for. To test if a cookie was successfully set, check for the cookie on a next loading page before the cookie expires. Expire time is set via the expire parameter. A nice way to debug the existence of cookies is by simply calling print_r($_COOKIE);. Nope. I log in, which sets the cookie, then close the browser, load up web-share.org.uk and then navigate to another page, which only then displays the cookie info I ask it to. You're probably checking on the same page you're setting the cookie. Orio. Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/#findComment-658255 Share on other sites More sharing options...
revraz Posted October 6, 2008 Share Posted October 6, 2008 Are you using relative or absolute links in your pages to other pages? Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/#findComment-658257 Share on other sites More sharing options...
trecool999 Posted October 6, 2008 Author Share Posted October 6, 2008 Are you using relative or absolute links in your pages to other pages? Absolute. Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/#findComment-658261 Share on other sites More sharing options...
revraz Posted October 6, 2008 Share Posted October 6, 2008 Use relative instead, you are probably changing domain names. Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/#findComment-658279 Share on other sites More sharing options...
trecool999 Posted October 6, 2008 Author Share Posted October 6, 2008 No domain name changes and it doesn't work with relative anyway. Besides, it stays with the domain defined in it's settings.php file. Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/#findComment-658283 Share on other sites More sharing options...
revraz Posted October 6, 2008 Share Posted October 6, 2008 Why wouldn't it work with relative? Post your Set code and your check code. The only way it would work somewhere and not elsewhere is because you are crossing domains. Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/#findComment-658287 Share on other sites More sharing options...
trecool999 Posted October 6, 2008 Author Share Posted October 6, 2008 I'm not sure why it doesn't. Things like images and links would redirect to non-existant places which was really annoying. Saying that, what would changing the links have anything to do with receiving the cookies anyway? Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/#findComment-658288 Share on other sites More sharing options...
revraz Posted October 6, 2008 Share Posted October 6, 2008 Because to me it sounds like you are setting the cookie on one domain, and by using a absolute path in your links, you are switching domains. Try it with relative path just to see if the cookie works. If not, post the code where you set the cookie along with the page name, and post the code where you check the cookie and that page name. Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/#findComment-658312 Share on other sites More sharing options...
DarkWater Posted October 6, 2008 Share Posted October 6, 2008 Are you sure you aren't setting a cookie on like, http://test.com and then going to http://www.test.com? That CAN make a difference, but you can fix it by putting a . in front of the domain name when setting the cookie, which makes it include all subdomains. Example: .test.com Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/#findComment-658315 Share on other sites More sharing options...
trecool999 Posted October 6, 2008 Author Share Posted October 6, 2008 I'm not really setting it with the URL included. I'm just doing a straight-forward setcookie(). Either way, it's called the same thing ($_COOKIE['WebShareCookie']) and Firefox sees it as the same cookie. I'm going to make this easier for myself (if this is possible): How can I save the session id to a cookie and then load the same session using the id the cookie has? Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/#findComment-658319 Share on other sites More sharing options...
DarkWater Posted October 6, 2008 Share Posted October 6, 2008 Try explicitly setting the domain parameter with the . included. Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/#findComment-658322 Share on other sites More sharing options...
trecool999 Posted October 6, 2008 Author Share Posted October 6, 2008 Reply above pls. Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/#findComment-658342 Share on other sites More sharing options...
revraz Posted October 6, 2008 Share Posted October 6, 2008 You are if you don't tell it otherwise. You are not considering any of the advice given, so I'll leave you with someone else to help you. I'm not really setting it with the URL included. I'm just doing a straight-forward setcookie(). Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/#findComment-658344 Share on other sites More sharing options...
trecool999 Posted October 6, 2008 Author Share Posted October 6, 2008 I'll set the domain then. But can somewhere answer my newwest question pls? Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/#findComment-658348 Share on other sites More sharing options...
DarkWater Posted October 6, 2008 Share Posted October 6, 2008 Uhh, you'd just use the session_start() function...because it sets a cookie and reads the sessid by itself. Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/#findComment-658353 Share on other sites More sharing options...
trecool999 Posted October 6, 2008 Author Share Posted October 6, 2008 Doesn't it get mixed with other page PHPSESSID's? :S Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/#findComment-658357 Share on other sites More sharing options...
DarkWater Posted October 6, 2008 Share Posted October 6, 2008 Doesn't it get mixed with other page PHPSESSID's? :S No, each domain has its own cookies, so you can be on PHPFreaks and have a session, and you can be on Facebook and have your own session too. Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/#findComment-658358 Share on other sites More sharing options...
trecool999 Posted October 6, 2008 Author Share Posted October 6, 2008 Still not working... Every time I reopen the browser, it deletes the cookie and starts a new session... How do I save the session cookie? Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/#findComment-658369 Share on other sites More sharing options...
DarkWater Posted October 6, 2008 Share Posted October 6, 2008 Session cookies don't persist between browser closes/openings unless you explicitly set a cookie expiry time. Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/#findComment-658375 Share on other sites More sharing options...
trecool999 Posted October 6, 2008 Author Share Posted October 6, 2008 I did. 0 . G2g anyway. See you guys tomorrow, hopefully when I will get over this problem. Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/#findComment-658377 Share on other sites More sharing options...
DarkWater Posted October 6, 2008 Share Posted October 6, 2008 0 means that it gets deleted when the browser closes. Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/#findComment-658379 Share on other sites More sharing options...
trecool999 Posted October 7, 2008 Author Share Posted October 7, 2008 Am I right in thinking setting it to a date in the past would work? Link to comment https://forums.phpfreaks.com/topic/127264-cookie-problem-very-frustrating/#findComment-658778 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.