Php Prog
Php Prog

Reputation: 23

using PHP sessions to verify username

I fell like this is a pretty simple fix, but i have tried so many different ways of doing this and have spent sooo many hours on google. basically a user logs in and my script makes sure that they are in my database. that works great, then i start my seesion.

session_start();
$_SESSION['log']=$username;
header("location:lindex.php");

On my next page, lindex.php, i call the session into order and try to set an if statement based on whether that value in $_SESSION['log'] is "support" or not, however it seems that no matter what the value in my session call is, it always performs the if statment i have tried basing it on string length, strstr, strpos, =="support. nothing is working. any ideas? here is lindex.php:

session_start();
if(empty($_SESSION['log'])){
echo "You must log in";
exit();}

if(strstr($_SESSION['log'], 'support'))
{
header("location:../sindex.php");
}

on a side note. if session is empty, it does exit script.

Upvotes: 2

Views: 181

Answers (2)

anon
anon

Reputation:

if(isset($_SESSION['log'] === "support")) 
{
echo "You are logged in ";
} else {

echo "You are not logged in ";
header("Location: http://site.com/login.php"); //should be always absolute URI
die();
}

Upvotes: 0

kittycat
kittycat

Reputation: 15045

if(strstr($_SESSION['log'], 'support'))

should be:

if($_SESSION['log'] == 'support'))

Upvotes: 1

Related Questions