Sessions not working?
Posted: Thu Dec 30, 2010 8:41 pm
Code: Select all
<?php
//Retrieve form data
$username = $_POST['username'];
$password = $_POST['password'];
//Access mySQL database to check the pass and user match
$mySQL_password = "PASSWORD";
$mySQL_username = "USERNAME";
$mySQL_localhost = "HOST";
$cnx = mysqli_connect($mySQL_localhost, $mySQL_username, $mySQL_password)
or die("Error: could not connect to database!");
$database = "sterli41_g4j";
$dbselect = mysqli_select_db($cnx, $database)
or die("Error: could not select database!");
$query = "SELECT * FROM members";
$result = mysqli_query($cnx, $query)
or die(mySQL_error());
$login = false;
while ($row = mysql_fetch_array($result))
{
$pass = $row['password'];
$user = $row['username'];
if($user == $username)
{
if($pass == $password)
{
$login = true;
}
}
}
if ($login)
{
session_start();
$_SESSION['loggedin'] = 1;
header ('Location: http://www.xxx.com/loggedin.php');
}
else
{
header ('Location: http://www.xxx.com/login_failed.php');
}
mysqli_close($cnx);
?>Code: Select all
<html>
<head>
<title>Games for Junk</title>
<link rel=StyleSheet href="http://www.xxx.com/style.css" TYPE="text/css">
</head>
<body>
<table width="100%" border="0" cellpadding="10">
<tr>
<td colspan="2" height="100" valign="top">
<?php
$data = file_get_contents('http://www.xxx.com/header.php');
echo($data);
?>
</td>
</tr>
<tr>
<td class="nav" valign="top" width="150">
<?php
$data = file_get_contents('http://www.xxx.com/navigation.php');
echo($data);
?>
</td>
<td valign="top">
<?php
if($_SESSION['loggedin'] == 1)
{
echo("<h4>You are now logged in.</h4>");
}
else
{
echo("<h4>An error occurred.</h4>");
}
?>
</form>
</td>
</tr>
<tr>
<td colspan="2" height="50" align="center">
<?php
$data = file_get_contents('http://www.xxx.com/footer.php');
echo($data);
?>
</td>
</tr>
</table>
</body>
</html>