| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
Senior Member
Join Date: Aug 2006
Posts: 389
|
Simple PHP question - Sessions
Hi there, I need to know something regarding sessions in PHP. Can't seem to find the answer through Google. I have a login page, and I'd like to have a little function that carries the username throughout the use of the website. Something like: You are logged in as (username).. You get my drift. Any help is appreciated! |
|
|
|
|
|
#4 (permalink) | ||
|
geek
|
Quote:
How do you differentiate users in your script/system? Probably by a user name or other form of id. (if you can't answer this or haven't come this far look for a login tutorial) Now store that information in a session variable/cookie (yummie). bang you're done. Quote:
|
||
|
|
|
#5 (permalink) |
|
i'm done, son
Join Date: Jan 2005
Posts: 12,262
|
Usually when someone logs in successfully, you set a valid $_SESSION for them. Let's say $_SESSION['username']. Then on subsequent pages you check if they're logged in using that: PHP Code:
|
|
|
|
#6 (permalink) |
|
Senior Member
Join Date: Sep 2006
Posts: 275
|
to be honest if you are creating a login system you should really have a file for functions and config especially if you are using classes so just include session start in that or make a more complex one that will check if a session exists and if not starts it again. More complex systems will log info and session ids in the db. Look at some login tutorials etc and you should get it pretty soon. Session variables work a lot like POST GET or standard variables as far as printing out comes but you need to understand how to set them, secure them and make them persistant. |
|
|
|
#7 (permalink) |
|
fucksocks™
Join Date: Jun 2005
Location: in the boosh
Posts: 1,578
|
When I was sussing sessions, I created a super basic submit/retrieve and kill to check it all worked. Take a look. There's a zip with the php source files. Help yourself. |
|
![]() |