Jump to content

Login problem.. :(


PoH

Recommended Posts

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

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.