Old 14-05-2007, 17:31   #1 (permalink)
pagey
Resident Cheese Expert
 
pagey's Avatar
 
Join Date: Aug 2006
Location: South Wales
Posts: 424
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!
  Reply With Quote
Old 14-05-2007, 18:20   #2 (permalink)
datahound
Spare Parts
 
datahound's Avatar
 
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 4,620
PHP Tutorial - Session

here's a start, for more search google by php session variables.
__________________
  Reply With Quote
Old 14-05-2007, 18:46   #3 (permalink)
pagey
Resident Cheese Expert
 
pagey's Avatar
 
Join Date: Aug 2006
Location: South Wales
Posts: 424
I'm interested more specifically in how to post information, which doesn't seem to be exaplined in that link, unless I'm misunderstanding the fundementals?
  Reply With Quote
Old 14-05-2007, 19:08   #4 (permalink)
gk
geek
 
gk's Avatar
 
Join Date: Oct 2006
Location: *.everywhere
Posts: 204
Send a message via ICQ to gk Send a message via AIM to gk Send a message via MSN to gk Send a message via Yahoo to gk
Quote:
Originally Posted by pagey
...unless I'm misunderstanding the fundamentals?


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:
"Why reinvent the wheel"? Simply because it's not round enough and I don't like the treads.
  Reply With Quote
Old 14-05-2007, 21:36   #5 (permalink)
pgo
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:
session_start();

if (isset(
$_SESSION['username']) {
  echo 
"You are logged in as".$_SESSION['username'];
} else {
  echo 
"You are not logged in.";

Remember, you need to use session_start(); in each PHP file that uses sessions.
  Reply With Quote
Old 15-05-2007, 04:51   #6 (permalink)
R1gM
Senior Member
 
R1gM's Avatar
 
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.
  Reply With Quote
Old 15-05-2007, 06:42   #7 (permalink)
mx
fucksocks™
 
mx's Avatar
 
Join Date: Jun 2005
Location: in the boosh
Posts: 1,611
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.
__________________
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8