i am having trouble with getting my login page to work could someone help me figure out where i am going wrong with this code please since it don’t redirect to the other page once logged in and don’t store the session thanks.
<?php
session_start();
include('mysql.php');
mysql_connect("$host", "$user", "$passwd");
mysql_select_db("mdb_sn027");
if(isset($_SESSION['username']))
{
die("You are already logged in!");
} // That bit of code checks if you are logged in or not, and if you are, you can't log in again!
if(isset($_POST['submit']))
{
$myusername=$_POST['usename'];
$mypassword=$_POST['pass'];
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM user WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
//If result matched $myusername and $mypassword,table is 1 row
if($count==1){
$_SESSION['myusername'] = $myusername;
header("location: .........");
}
else {
if (isset($_SESSION['myusername'])) {
unset($_SESSION['myusername']);
}
echo "Wrong Username or Password";
}
}
?>
the textbox i named usename
when you type in the password and username it redirects to a new page but there is also a webpage where you have to be logged on to view it. when you click to access after password and username have been accepted it still redirects you to the login page.
1: Consider updating the script to use mysqli or PDO.
2: Location has a capital L.
3: the if inside your outer Else clause will never evaluate to true.
4: You’re not detecting the session because of the following: