I know you guys constantly get questions about sessions. However, I’ve read all of the manuals and tutorials that I could possibly Google and am still having some trouble. I have a login page (test_login.php):
[CODE]<?php
session_start();
if($_POST[‘submit’])
{
# connect to db
include ‘db_connect.php’;
# set user/pass
$_SESSION[‘user’] = strip_tags(substr($_POST[‘tfUser’],0,32)); #from form textfield tfUser
$_SESSION[‘pass’] = strip_tags(substr($_POST[‘tfPass’],0,32)); #from form textfield tfPass
$query = “SELECT * FROM test_admin WHERE
user = ‘”. mysql_real_escape_string($_SESSION[‘$user’]).”‘ AND
pass= ‘”. mysql_real_escape_string($_SESSION[‘$pass’]).”‘”;
$result = mysql_query($query) or die( “QUERY ERROR: ” . mysql_error() );
if(mysql_num_rows($result) > 0) # found a match
{
$_SESSION[‘logged’] = TRUE;
header(“Location: test.php”);
}
else
{
$error_invalid = “<font size=’1′ color=’#FF0000′ face=’Arial’>Invalid username and/or password.”;
}
}
?>
If a match is found then the user is directed to test.php:
[CODE]<?php session_start();
if ( $_SESSION[‘logged’] = TRUE )
{
?>
<html>
<head>
</head>
<body>
// here I have some html
</body>
</html>
<?php
}
else
{
header(“Location: test_login.php”); # redirect back to login page
}
?>
Earlier today I had it accepting my login with the correct user/pass. However, I tried to change the code so that I could not surf onto test.php without first logging in and I ran into trouble. Now when I try to login with the correct user/pass, I am given my error of, “Invalid username and/or password”. ? What am I doing wrong? Thanks in advance!