Jump to content


Photo

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


  • Please log in to reply
2 replies to this topic

#1 essjay_d12

essjay_d12
  • Members
  • PipPipPip
  • Advanced Member
  • 121 posts

Posted 13 March 2006 - 11:04 AM

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

#2 webwiese

webwiese
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 13 March 2006 - 11:14 AM

[!--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) View Post[/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



#3 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 13 March 2006 - 11:23 AM

at the top of every page i use sessions, i always include('session.php');

which contains..

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

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users