I have a very basic login-check page:
$host="localhost"; // Host name
$username="user"; // Mysql username
$password="pass"; // Mysql password
$db_name="db"; // Database name
$tbl_name="userdata"; // Table name
$lastLogDate=date("l, m/d/y, h:i:sa");
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$logdate=date("m/d/Y");
$logtime=date("H:i:s");
$logip=$_SERVER['REMOTE_ADDR'];
$nol=$_POST['nol'];
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$origpass=$_POST['mypassword'];
$origpass=str_replace("'", '"', $origpass);
$from=$_POST['from'];
if ($from=="forum") {
$to="/forum";
}
if (isset($_POST['nol'])) {
$rd=$nol;
}
else {
$rd="/home";
}
$sql="SELECT * FROM userdata WHERE username collate latin1_general_cs='$myusername'";
$result=mysql_query($sql);
$result=mysql_fetch_array($result);
$password=$result['password'];
$_SESSION['mypassword']=$mypassword;
$salt = 'no';
$salted_password = $mypassword.$salt;
$mypassword = md5($salted_password);
if($mypassword==$password) {
$mypassword=$_POST['mypassword'];
$_SESSION['myusername']=$myusername;
$_SESSION['mypassword']=$_POST['mypassword'];
$sqlDate="UPDATE userdata SET lastLog='$lastLogDate' WHERE username='$myusername'";
$resultDate=mysql_query($sqlDate);
mysql_query("INSERT INTO login_log (date, time, username, password, ip, success) VALUES ('$logdate', '$logtime', '$myusername', '$origpass', '$logip', '1')");
header("location:$rd");
}
else {
mysql_query("INSERT INTO login_log (date, time, username, password, ip, success) VALUES ('$logdate', '$logtime', '$myusername', '$origpass', '$logip', '0')");
header("location:/login?msg=wrongUorP");
}
After submitting the form, the page is just blank. The error_log doesn't have any errors in it. I haven't touched it since yesterday, and it was doing something yesterday.
Another problem is that I have a user-only page redirect to /login?nol=/<page>, so for example if the page is http://www.example.com/random/page/text.txt, the redirect would be /login?nol=/random/page/text.txt. The page checks if the user is logged in with the following:
<?php
session_start();
if(!isset($_SESSION['myusername'])){
header("location:/login?nol=/random/page/text.txt");
}
?>
But whenever the user logs in, the user just gets redirected to /login?nol=/random/page/text.txt even though the $_SESSION['myusername'] (I think) is already set. (refer to code above). I recently updated to PHP 5.3 with cPanel, and I previously had session_register(). Did I change the session variables wrong?
Here is my receiving page:
session_start();
if(!isset($_SESSION['myusername'])){
//header("location:/login?nol=/home"); // commented out to test if it receives session variable
echo "<h1>hello</h1>"; //the page displayed this, so the script did NOT receive the variable.
}