Jump to content

Cookies


coolgamer48

Recommended Posts

Allright, so I have this site with cookies: http://alecbenzer.awardspace.com/cookietest1/cookietest1.php. I'm just using it for testing.This is what happens:IF you aren't signed it the site says Hello Guest and offers a sign-in form. IF you are, it says Hello, and then whatever username you entered, and then offers a signout link. Couple of problems:when you press sign in, the .php files sets the value of $_COOKIE["user"], but when I atempt to read it, it doesn't work. isset even returns false, but setcookie returns true. When I refresh the page, setcookie doesn't run again, but now isset returns true, and I can read the value of $_COOKIE["user"].Coupleof more problemss - g2g rite now, ill edit this later.

Link to comment
Share on other sites

You can't read the cookie immediately after setting it, you need to open the page again to read the cookie.I recommend passing through a "you have just logged in" page and then make it redirect to the next page with javascript or a <meta> redirect tag.

Link to comment
Share on other sites

Cookies get passed back and forth between the client and the server through the Requests and Responses. If you set a cookie on the server, that cookie gets added to the Response. If you read a cookie on the server, you are reading that Cookie from the Request. To further what Ingolme was saying, if you set a cookie, you have to send out the Response and wait for the next Request before you can actually read that cookie.

Link to comment
Share on other sites

Allright, i figured there's some sort of rule around reading cookies. So basically, the page has to be refreshed AFTER the setcookie() function. Okay - that's was my major problem - I'll use the you are now logged in page for that.Okay - now there are still some other probs i found:On some computers, if you click sign out, you just get stuck on the sign out page, even though its supposed to redirect you to the original sign-in page. Does that happen for youAlso, I have trouble when using the back button on the borwser. is there any way to get a page to auto-refresh when you go back to it?thanks.

Link to comment
Share on other sites

This is the format of your meta tag:<meta content="3;cookietest1.php" http-equiv="Refresh">This is the format it should be in:<meta http-equiv="refresh" content="10;url=http://wikipedia.org">The major difference is the url=You can't force a refresh, but you can tell the browser not to cache the page. You can do that by either sending a header or using a meta tag, do a Google search for disabling caching to see more.

Link to comment
Share on other sites

The browser will save the page on the local hard drive and if it goes back to the same URL it will check to see if it's saved in the cache first. If so, it will load the file on disk instead of getting the page from the server. Any page that you don't want the browser to save, where it always gets the page from the server, you should disable caching on.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...