BlueSkyIS Posted September 22, 2007 Share Posted September 22, 2007 DO NOT USE session_register and session_destroy. They are deprecated. Quote Link to comment https://forums.phpfreaks.com/topic/70276-my-login-script/page/2/#findComment-352983 Share on other sites More sharing options...
forumnz Posted September 22, 2007 Author Share Posted September 22, 2007 DO NOT USE session_register and session_destroy. They are deprecated. Does this mean I shouldn't use sessions? Quote Link to comment https://forums.phpfreaks.com/topic/70276-my-login-script/page/2/#findComment-352986 Share on other sites More sharing options...
rarebit Posted September 22, 2007 Share Posted September 22, 2007 I can't find anywhere that it say's session_destroy is depricated?? http://uk3.php.net/manual/en/ref.session.php http://uk3.php.net/manual/en/function.session-destroy.php It's just that I use it currently, therefore what use instead? Quote Link to comment https://forums.phpfreaks.com/topic/70276-my-login-script/page/2/#findComment-352987 Share on other sites More sharing options...
darkfreaks Posted September 22, 2007 Share Posted September 22, 2007 no it says nothing on PHP.net about them being deappreciated. id still use them read up on your sessions and how to use them http://us.php.net/manual/en/function.session-register.php Quote Link to comment https://forums.phpfreaks.com/topic/70276-my-login-script/page/2/#findComment-352988 Share on other sites More sharing options...
forumnz Posted September 22, 2007 Author Share Posted September 22, 2007 What is wrong with this. I have made it set a session with the users id as the uid. It displays "UID =" and thats it. Thanks, Sam. <?php include('connect.php'); mysql_select_db("bbmembers", $con); if(count($_POST)>0) { $username=$_POST["username"]; $password=$_POST["password"]; $password=md5($password); $sql="SELECT * FROM members WHERE username=\"$username\" AND password=\"$password\""; $rs=mysql_query($sql); //execute the query if(mysql_num_rows($rs)==1) { $uid = $row["id"]; session_start(); $_SESSION['user'] = $uid; // store session data echo "UID = ". $_SESSION['user']; //retrieve data }else{ if(mysql_num_rows($rs)==0) { //invalid username of password //redirect to login page header("Location: login.php"); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/70276-my-login-script/page/2/#findComment-352992 Share on other sites More sharing options...
ted_chou12 Posted September 22, 2007 Share Posted September 22, 2007 Hang on..... got it!! Now i just need it to set a cookie. I will try that myself. Should I use cookies or sessions? You can use both cookies and sessions, for cookies, the format is like: setcookie("username", $_SESSION['username'], time()+60*60*24*30, "/"); setcookie("password", $_SESSION['password'], time()+60*60*24*30, "/"); for sessions: $_SESSION["username"] = $username; $_SESSION["password"] = $password; Ted Quote Link to comment https://forums.phpfreaks.com/topic/70276-my-login-script/page/2/#findComment-352993 Share on other sites More sharing options...
darkfreaks Posted September 22, 2007 Share Posted September 22, 2007 cookies is alot unsafer. Quote Link to comment https://forums.phpfreaks.com/topic/70276-my-login-script/page/2/#findComment-352994 Share on other sites More sharing options...
rarebit Posted September 22, 2007 Share Posted September 22, 2007 Looks like you haven't used 'session_start()', even though this maybe dne automatically... Quote Link to comment https://forums.phpfreaks.com/topic/70276-my-login-script/page/2/#findComment-352995 Share on other sites More sharing options...
darkfreaks Posted September 22, 2007 Share Posted September 22, 2007 you need session_start(); followed by $username=$_SESSION[username]; $password=$_SESSION[password]; then at the end of the code put session_destroy(); Quote Link to comment https://forums.phpfreaks.com/topic/70276-my-login-script/page/2/#findComment-352996 Share on other sites More sharing options...
forumnz Posted September 22, 2007 Author Share Posted September 22, 2007 Like this: <?php session_start(); $username=$_SESSION[username]; $password=$_SESSION[password]; $id=$_SESSION[uid]; include('connect.php'); mysql_select_db("bbmembers", $con); if(count($_POST)>0) { $username=$_POST["username"]; $password=$_POST["password"]; $password=md5($password); $sql="SELECT * FROM members WHERE username=\"$username\" AND password=\"$password\""; $rs=mysql_query($sql); //execute the query if(mysql_num_rows($rs)==1) { $uid = $row["id"]; session_start(); $_SESSION['user'] = $uid; // store session data echo "UID = ". $_SESSION['user']; //retrieve data }else{ if(mysql_num_rows($rs)==0) { //invalid username of password //redirect to login page header("Location: login.php"); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/70276-my-login-script/page/2/#findComment-352999 Share on other sites More sharing options...
LiamProductions Posted September 22, 2007 Share Posted September 22, 2007 Where are you including the mysql connection? Quote Link to comment https://forums.phpfreaks.com/topic/70276-my-login-script/page/2/#findComment-353001 Share on other sites More sharing options...
darkfreaks Posted September 22, 2007 Share Posted September 22, 2007 example <?php session_start(); if (isset($_SESSION['username'])){ echo "User : ".$_SESSION['username']; unset($_SESSION['username']); } else { echo "Set the username"; $_SESSION['username'] = 'John'; ?> http://www.phpf1.com/tutorial/php-sessions.html good session tutorial Quote Link to comment https://forums.phpfreaks.com/topic/70276-my-login-script/page/2/#findComment-353002 Share on other sites More sharing options...
forumnz Posted September 22, 2007 Author Share Posted September 22, 2007 This is what I currently have... why is it not working? <?php session_start(); $_SESSION['uid'] = '$id'; include('connect.php'); mysql_select_db("bbmembers", $con); if(count($_POST)>0) { $username=$_POST["username"]; $password=$_POST["password"]; $password=md5($password); $sql="SELECT * FROM members WHERE username=\"$username\" AND password=\"$password\""; $rs=mysql_query($sql); //execute the query if(mysql_num_rows($rs)==1) { //Set Session session_start(); $_SESSION['id'] = $id; // store session data echo "UID = ". $_SESSION['id']; //retrieve data }else{ if(mysql_num_rows($rs)==0) { //invalid username of password //redirect to login page header("Location: login.php"); } } } ?> The connect.php is connecting to the db. Thanks, Sam. Quote Link to comment https://forums.phpfreaks.com/topic/70276-my-login-script/page/2/#findComment-353006 Share on other sites More sharing options...
rarebit Posted September 22, 2007 Share Posted September 22, 2007 Your using session start twice?? Quote Link to comment https://forums.phpfreaks.com/topic/70276-my-login-script/page/2/#findComment-353008 Share on other sites More sharing options...
forumnz Posted September 22, 2007 Author Share Posted September 22, 2007 I know I am stupid.... haha... what do i do? Quote Link to comment https://forums.phpfreaks.com/topic/70276-my-login-script/page/2/#findComment-353009 Share on other sites More sharing options...
darkfreaks Posted September 22, 2007 Share Posted September 22, 2007 take out the second session_start? Quote Link to comment https://forums.phpfreaks.com/topic/70276-my-login-script/page/2/#findComment-353012 Share on other sites More sharing options...
forumnz Posted September 22, 2007 Author Share Posted September 22, 2007 OK, it still just displays "UID=" Quote Link to comment https://forums.phpfreaks.com/topic/70276-my-login-script/page/2/#findComment-353014 Share on other sites More sharing options...
darkfreaks Posted September 22, 2007 Share Posted September 22, 2007 <?php $_SESSION['uid'] = $id; echo "UID=" $id; ?> Quote Link to comment https://forums.phpfreaks.com/topic/70276-my-login-script/page/2/#findComment-353017 Share on other sites More sharing options...
forumnz Posted September 22, 2007 Author Share Posted September 22, 2007 in my db it is id not uid. Does that help? Quote Link to comment https://forums.phpfreaks.com/topic/70276-my-login-script/page/2/#findComment-353019 Share on other sites More sharing options...
darkfreaks Posted September 22, 2007 Share Posted September 22, 2007 change it to the exact field then <?php $_SESSION['id'] = $id; echo "UID=" $id; ?> Quote Link to comment https://forums.phpfreaks.com/topic/70276-my-login-script/page/2/#findComment-353020 Share on other sites More sharing options...
rarebit Posted September 22, 2007 Share Posted September 22, 2007 Here's how I make sure the session is started and how to get the session_id: // START SESSION try { if ( !@ ( session_id() ) ) throw new Exception ("oh no!"); } catch (Exception $e) { //print 'INCLUDE ERROR!!!<br>'; //return -1; session_start(); } // GET CURRENT SESSION ID try { if ( !@ ( $sess['sess_id'] = session_id() ) ) throw new Exception ("oh no!"); } catch (Exception $e) { session_destroy(); session_start(); $sess['sess_id'] = session_id(); } Use whatever you want instead of $sess['sess_id']... Quote Link to comment https://forums.phpfreaks.com/topic/70276-my-login-script/page/2/#findComment-353026 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.