Jump to content

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


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.