Welcome to WebmasterWorld Guest from 54.159.190.106

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP Sessions

Best way to keep track of users

   
5:20 pm on Jan 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello everyone,

I am building a members section for my site and I was curious what the best way to go about remember users would be. The site I'm working on is mainly an information site which will have the ability for people to login and view reviews on products and also allow manufacturers to login and upload information about their products.

I was curious how I should remember a user is on my site. Currently, I have a $_SESSION[''] variable that remembers them but when they open a new browser it forgets them. Also this posses problems if they are still viewing my site but want to have 2 browsers open while on my site.

Is this the best method? Also considering they login - they will have to relogin everytime they come back to my site. This makes me wonder if I should use cookies. I have never used them before. Would they be the best solution? Are they secure?

Any information would be great :)

Thanks!

Wes

5:31 pm on Jan 25, 2005 (gmt 0)

10+ Year Member



This is because your sessions are expiring on closing the browser. You can set the session lifetime with ini_set():

ini_set('session.cookie_lifetime',(3600*24*365)); // makes cookie good for a year

One problem with that is the server's temp directory might get clogged with saved sessions. If you have a high traffic site, this could cause problems. You can either use cookies, or make the cookie lifetime something like 30 days.

See [php.net...] for more information.

Hope this helps!

5:44 pm on Jan 25, 2005 (gmt 0)

10+ Year Member



One problem with that is the server's temp directory might get clogged with saved sessions

If this is likely to become a problem - you could always set a custom session handler and write everything into a database :)

http://uk.php.net/manual/en/function.session-set-save-handler.php [uk.php.net]

Cheers,
JP

7:01 pm on Jan 25, 2005 (gmt 0)

10+ Year Member



Awesome JPJones, I didn't know you could do that. Good tip.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month