|
-
Mar 23rd, 2004, 10:42 AM
#1
Cookies, PHP, and refreshing
OK, I'm working on a modification to a webpage where I need to set cookies for a particular functionality. Having worked with cookies & PHP before, I know that the cookie value will not take until AFTER the page is refreshed. Since this cookie will be set on every page, I don't really want to refresh it everytime. So, I want to now if I jsut setCookie, then the user clicks a link, will that be sufficient, or do I really need to find a different way to do this? Secondly, if I setcookie, don't refresh, and then the user goes to a new website, sy by either a click to the new site, or by entering an address in the address bar, will the cookie remain intact (it's going to be a session variable, so I don't care once they close their browser.)?
TG
-
Mar 23rd, 2004, 06:42 PM
#2
-
Mar 23rd, 2004, 07:21 PM
#3
Stuck in the 80s
Re: Cookies, PHP, and refreshing
I'm pretty confused as to what you want. What data is being saved in the cookie? Is it login information (my best guess since you're resetting it everytime)?
Originally posted by techgnome
So, I want to now if I jsut setCookie, then the user clicks a link, will that be sufficient, or do I really need to find a different way to do this?
What will the link go to? Will it just be a link to the current page (a way to refresh)? If so, yes.
Originally posted by techgnome
Secondly, if I setcookie, don't refresh, and then the user goes to a new website, sy by either a click to the new site, or by entering an address in the address bar, will the cookie remain intact (it's going to be a session variable, so I don't care once they close their browser.)?
Cookies will stay for as long as you set them. The default expires when the browser window closes (not when they navigate away).
I'm not sure if I'm helping you at all with any of this, since I'm still confused.
-
Mar 23rd, 2004, 09:13 PM
#4
Hmmm...... how can I describe this....
OK... let me try explaining it like this:
User hits my site for the first time.
I take the current URL and the page name (Home) and put them into an array.
I then serialize the array and store it in a cookie.
Somewhere later on the page, I'll use the array to show where on my site they've been (In this case it will simply list "Home" as a link.)
Let's say they then click on a link that takes them into a postinc caregory, "Brewmeister".
When the page loads, it finds the cookie, extracts it, and unserializes it into the array (which has the link and title to my "Home" page), and adds the new page to the array. The array should now contain two items, "Home" and "Brewimeister." I reserialize the array and stuff it back into the cookie.
Again, later I'll use the array to shwo where the user was: "Home" -> "Brewmeister"
As the user goes trapising through my site, I want to grab the cookie, unserialize the array, add to the array, then serialize the array back into the cookie.
If it helps, there is also this post where I attempt to describe *** I am doing...
http://wordpress.org/support/4/3424#post-5
TG
-
Mar 23rd, 2004, 11:40 PM
#5
Loading a new page that will open the cookie will suffice and count as a page refresh. If your user left your page and had "Home -> Brewmister" or whatever, and then came back and entered on the Home page, it would add to the array like "Home -> Brewmister -> Home".. if that's what you wanted, then what you're thinking of is totally possible and you're on your way to doing it.
If you are wanting to also show the current page they are on, you can't do it with using ONLY cookies, but you can grab your "current page" variable and print it out along with the cookie.
Also, the cookie will remain intact until it has met it's expiry date, whether it be a session cookie, where it expires when the user has their browser closed, or it's expiry is in 30 days.
Hope that helps..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|