PoH Posted December 13, 2010 Share Posted December 13, 2010 Hi, I had my login working and now it has stopped working. Idk why but heres the files: <?php ob_start(); include 'inc/open.php'; // Define $ip and $password $ip=$_POST['ip']; $password=$_POST['password']; // To protect MySQL injection (more detail about MySQL injection) $ip = stripslashes($ip); $password = stripslashes($password); $ip = mysql_real_escape_string($ip); $password = mysql_real_escape_string($password); $sql="SELECT * FROM status WHERE ip='$ip' and password='$password'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $ip and $password, table row must be 1 row if($count==1){ // Register $ip, $password and redirect to file "login_success.php" session_register("ip"); session_register("password"); header("location:lindex.php"); } else { echo "Wrong ip or Password"; } ob_end_flush(); ?> And then I want my index page to recognize this and do the following: <?php session_start(); include('inc/open.php'); if(session_is_registered('ip')){ echo "<h5><a href='index.php'>Home</a> | <a href='addnew.php'>Add New Sever</a> | <a href='offline.php'>View Offline Servers</a> | <a href='editserver.php'>Server CP</a></h5>"; }else{ echo "<h5><a href='index.php'>Home</a> | <a href='addnew.php'>Add New Sever</a> | <a href='offline.php'>View Offline Servers</a> | <a href='editlogin.php'>Login</a></h5>"; } ?> Thank you. Problem: the login is working and redirecting to index.php however index.php is not recognizing that user is logged on. Link to comment https://forums.phpfreaks.com/topic/221557-login-problem/ Share on other sites More sharing options...
joel24 Posted December 13, 2010 Share Posted December 13, 2010 session_register(); This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged. use session_start(); and $_SESSION(); Link to comment https://forums.phpfreaks.com/topic/221557-login-problem/#findComment-1146917 Share on other sites More sharing options...
priti Posted December 13, 2010 Share Posted December 13, 2010 on index page try printing session. print_r($_SESSION); and see if you can find your variable registered in session. Link to comment https://forums.phpfreaks.com/topic/221557-login-problem/#findComment-1146918 Share on other sites More sharing options...
PoH Posted December 13, 2010 Author Share Posted December 13, 2010 Neither worked. Link to comment https://forums.phpfreaks.com/topic/221557-login-problem/#findComment-1146941 Share on other sites More sharing options...
priti Posted December 13, 2010 Share Posted December 13, 2010 I have no idea if you have two different file or one single but session_start(); needs to be very first line in your code. Link to comment https://forums.phpfreaks.com/topic/221557-login-problem/#findComment-1146944 Share on other sites More sharing options...
PoH Posted December 14, 2010 Author Share Posted December 14, 2010 It is at the very top. First line Link to comment https://forums.phpfreaks.com/topic/221557-login-problem/#findComment-1146947 Share on other sites More sharing options...
priti Posted December 14, 2010 Share Posted December 14, 2010 I am referring to this <?php session_start(); ob_start(); include 'inc/open.php'; // Define $ip and $password $ip=$_POST['ip']; $password=$_POST['password']; Link to comment https://forums.phpfreaks.com/topic/221557-login-problem/#findComment-1146950 Share on other sites More sharing options...
joel24 Posted December 14, 2010 Share Posted December 14, 2010 <?php session_start(); ob_start(); include 'inc/open.php'; // Define $ip and $password $ip=$_POST['ip']; $password=$_POST['password']; // To protect MySQL injection (more detail about MySQL injection) $ip = stripslashes($ip); $password = stripslashes($password); $ip = mysql_real_escape_string($ip); $password = mysql_real_escape_string($password); $sql="SELECT * FROM status WHERE ip='$ip' and password='$password'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $ip and $password, table row must be 1 row if($count==1){ // Register $ip, $password and redirect to file "login_success.php" $_SESSION("ip") = $ip; $_SESSION("password") = $password; header("location:lindex.php"); } else { echo "Wrong ip or Password"; } ob_end_flush(); ?> and then on lindex.php (index.php?) you can use print_r($_SESSION); which will print all the set sessions variables. And I don't know why you're putting the password into the session?? You should just verify that the password is correct then set a session variable, say authenticated to true.... and to check if a user is logged in, you can write a function or just do if ($_SESSION['authenticated']==true) { //whatever } else { exit("Not authenticated"); } Link to comment https://forums.phpfreaks.com/topic/221557-login-problem/#findComment-1146956 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.