kingb00zer Posted March 25, 2011 Share Posted March 25, 2011 Hey I have recently completed sign up and log in forms for a site I am working on and now that I can log in I am wondering weather I have to start session on every page viewable after logging in or if the session stays connected as I surf through the pages.I have provided what code I used to log in below in case you need to see it.check login.php <?phpinclude("connection.php");$username= $_POST['username'];$password= $_POST['password'];// check if username and passwords match$checkuser= "SELECT * FROM users WHERE username = '$username' and password = '$password'";$result=mysql_query($checkuser);$count=mysql_num_rows($result);if ($count == 1){session_register("username");session_register("password");header("location:login_success.php");}else {echo "Wrong Username or Password";}?> login_sucess.php <?session_start();if(!session_is_registered($username)){header("location:welcome.php");}?> welcome.php <html><head><link rel="stylesheet" type="text/css" href="gamestyles.css" /> </head><title> the site</title> <body bgcolor="black"> <h1 align="center" class="one"> Welcome to the site </h1> <h1 align="center" class="one"> <a href="drugmarket.html"> CLICK HERE TO ENTER</a> </h1> </body> </html> Basically asking if I need to add any php session code to welcome.php and of course the pages viewable in the rest of the members only area. Link to comment Share on other sites More sharing options...
chokk Posted March 25, 2011 Share Posted March 25, 2011 Yep, you have to initiate sessions on pages you want to limit to users only. Link to comment Share on other sites More sharing options...
Ingolme Posted March 25, 2011 Share Posted March 25, 2011 I don't recommend using session_register() and session_is_registered(). The PHP manual states that they are deprecated and shouldn't be relied on.Talking about deprecated, the bgcolor attribute is deprecated as well. Link to comment Share on other sites More sharing options...
kingb00zer Posted March 25, 2011 Author Share Posted March 25, 2011 Yep, you have to initiate sessions on pages you want to limit to users only.thank youI don't recommend using session_register() and session_is_registered(). The PHP manual states that they are deprecated and shouldn't be relied on.Talking about deprecated, the bgcolor attribute is deprecated as well.How should I go about using an alternative for session_register() And session_is_registered()?and as for bgcolor i have been meaning to set up a style for body in my style sheet, just been a bit lazy on that lol. Link to comment Share on other sites More sharing options...
birbal Posted March 25, 2011 Share Posted March 25, 2011 you can use super global array $_SESSION['username']='somename'and as you can do to check a variable has been set or not you can do it with also. eg isset()eg if(isset($_SESSION['username'])) Link to comment Share on other sites More sharing options...
birbal Posted March 25, 2011 Share Posted March 25, 2011 you can use super global $_SESSION array to assign....$_SESSION['username']='somename'and as you can do to check a variable has been set or not you can do it with also. eg isset()eg if(isset($_SESSION['username'])) Link to comment Share on other sites More sharing options...
kingb00zer Posted March 26, 2011 Author Share Posted March 26, 2011 thanks I'll try that Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.