Jump to content

Archived

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

essjay_d12

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
at the top of every page i use sessions, i always include('session.php');

which contains..

[code]session_start();
function check_session() {
if (!isset($_SESSION['username']) die ("please login");
}[/code]

Share this post


Link to post
Share on other sites

×

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.