Forum Moderators: coopster

Message Too Old, No Replies

php session vars

         

partha

5:01 pm on May 22, 2005 (gmt 0)

10+ Year Member



I'm seeing conflicting info regarding session variables in php, so hopefully you guys can straigten me out and explain why or why not I would want to use them for my purposes.

first of all, this site (http://www.phpfreaks.com/tutorials/41/0.php) says:
-"Cookies are about 30% unreliable right now and it's getting worse every day"
-"PHP has a great set of functions that can achieve the same results of Cookies and more without storing information on the user's computer"

here's what I need to have:
A. run a little script when the user first arrives anywhere on my site, which then sets a little register to true if they meet certain conditions. this variable will be visible and set to true on every script they access on my site for the duration of THAT session. if they close the browser and then load up my site again later that day or month or whatever, this process should repeat.
B. identify when a user that has come to my site in the past returns at any time in the future (like you can do easily with traditional cookies).

1. how would I do both of these things in php?
2. is it true that cookies are only 30% reliable?
3. are your solutions in php 100% reliable?

dcrombie

8:55 am on May 23, 2005 (gmt 0)



There is no 100% reliable way to identify a repeat visitor. The IP address and user-agent can both change, and cookies can be deleted.

However, if someone does return to the site, and does have a cookie that you set, you can be 99% sure that it's a return visitor.

partha

1:50 pm on May 23, 2005 (gmt 0)

10+ Year Member



but what about these "sessions"? aren't they sort of like a server side cookie? so wouldn't it be 100% reliable?

dcrombie

2:01 pm on May 23, 2005 (gmt 0)



Sessions are nothing more than beefed-up cookies with a fallback option of having the id passed in the URL.

partha

1:59 pm on May 24, 2005 (gmt 0)

10+ Year Member



ok

partha

2:01 pm on May 24, 2005 (gmt 0)

10+ Year Member



for A. part in my first post, is there a way to set a cookie to expire when the user closes the browser?

dcrombie

2:18 pm on May 24, 2005 (gmt 0)



setcookie [php.net] - the expire parameter