Jump to content

session code not working


this.user

Recommended Posts

I have this code, that determines if the user has a session running, if not checks for a cookie and if they have cookie create a session for them if not, send them to the index page.

 

However, it does not work. It does not send the user back to the index page when appropriate.

 

Can someone please tell me whats wrong i have no clue.

 

<?php session_start();
$sessionuser = $_SESSION['user'];
$sessionpassword = $_SESSION['password'];
$ui = "";
$sessionquery = "SELECT id FROM user WHERE username = '" . trim($sessionuser) . "' AND password = '" . trim($sessionpassword) ."'";
$query_sessionresult = mysql_query($sessionquery) or die(mysql_error());
if (mysql_num_rows($query_sessionresult) == 0)
{
  	if(isset($_COOKIE['user'])&&(isset($_COOKIE['password'])))
	{
		$cookieuser = mysql_real_escape_string($_COOKIE['user']);
		$cookiepassword = mysql_real_escape_string($_COOKIE['password']);
		$cookiequery = "SELECT id FROM user WHERE username = '$cookieuser' AND password = '$cookiepassword'";
		$query_cookieresult = mysql_query($cookiequery) or die(mysql_error());
		if(mysql_num_rows($query_cookieresult) == 0)
		{
			header("Location: index.php");
			die();
		}
		else
		{
			$query_cookierow = mysql_fetch_array($query_cookieresult);
			$ui = $query_cookierow['id'];
		}
	}
	else
	{
		header("Location: index.php");
		die();
	}
}
else
{
	$query_sessionrow = mysql_fetch_array($query_sessionresult);
	$ui = $query_sessionrow['id'];
}?>

Link to comment
https://forums.phpfreaks.com/topic/179937-session-code-not-working/
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.