essjay_d12 Posted March 13, 2006 Share Posted March 13, 2006 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!!!!ThanksD Link to comment https://forums.phpfreaks.com/topic/4820-sessions-unsure-just-need-confirmation/ Share on other sites More sharing options...
webwiese Posted March 13, 2006 Share Posted March 13, 2006 [!--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!!!!ThanksD[/quote]Hi,session_start() must be set before any output of your script. For identifying a logged user just asksession_start();if (isset($_SESSION['loginname']) { ..... code .....} // ifFor logout I suggest a unset($_SESSION).webwiese Link to comment https://forums.phpfreaks.com/topic/4820-sessions-unsure-just-need-confirmation/#findComment-16946 Share on other sites More sharing options...
keeB Posted March 13, 2006 Share Posted March 13, 2006 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] Link to comment https://forums.phpfreaks.com/topic/4820-sessions-unsure-just-need-confirmation/#findComment-16948 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.