Jump to content

Sessions ..... unsure... just need confirmation!


essjay_d12

Recommended Posts

I want to remember the users username and password

i've been told to look into sessions, from what i've learned would I be right in simply doing the following...

$_SESSION['loginname'] = $_POST['loginname'];

$_SESSION['password'] = $_POST['password'];

and then just

session_start();

at the beginning of each page where it is needed?

Then call $_SESSION['loginname'] when I need to access the database?

then when they log out simply....

$_SESSION['loginname'] = '';

$_SESSION['password'] = '';

i'm NEW!!!!!!!! SORRY!!!!

Thanks

D
Link to comment
https://forums.phpfreaks.com/topic/4820-sessions-unsure-just-need-confirmation/
Share on other sites

[!--quoteo(post=354455:date=Mar 13 2006, 12:04 PM:name=Essjay_d12)--][div class=\'quotetop\']QUOTE(Essjay_d12 @ Mar 13 2006, 12:04 PM) [snapback]354455[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I want to remember the users username and password

i've been told to look into sessions, from what i've learned would I be right in simply doing the following...

$_SESSION['loginname'] = $_POST['loginname'];

$_SESSION['password'] = $_POST['password'];

and then just

session_start();

at the beginning of each page where it is needed?

Then call $_SESSION['loginname'] when I need to access the database?

then when they log out simply....

$_SESSION['loginname'] = '';

$_SESSION['password'] = '';

i'm NEW!!!!!!!! SORRY!!!!

Thanks

D
[/quote]


Hi,

session_start() must be set before any output of your script. For identifying a logged user just ask

session_start();
if (isset($_SESSION['loginname']) {

..... code .....

} // if

For logout I suggest a unset($_SESSION).

webwiese

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.