I'm just getting in to MySQL and PHP--and I'm just trying to create a simple login system for a project we're testing. I've connected and created the login logic just fine, but now I can't for the life of me get the session variables to carry over to the new pages. Could someone please show me the correct way to do this?
Here is my login script--which is activated by submitting a form:
<?php
session_start();
$link = mysql_connect('xxxxxxx.ipowermysql.com', 'xxxxxx', 'xxxxxx');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db(austinhabich_IC_20090511_174535) or die(msql_error());
$email=$_POST['email'];
$password=$_POST['password'];
$sql="SELECT * FROM player WHERE email='$email' and password='$password'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
$_SESSION['status'] = "1";
header("location: main.php");
}
else {
echo "Wrong Username or Password";
}
?>
And here is the page it redirects to:
<?php session_start(); ?>
...doctype stuff...
<html
xmlns="http://www.w3.org/1999/xhtml">
<head> <meta http-equiv="Content-Type"
content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?
echo $_SESSION['status'];
?> </body> </html>
In this case, I'm just trying to even get the session variable to register, so I'm testing by attempting to print the variable's data. I've been trying to use isset and have it redirect back to the login page. The redirect worked, but it happened every time since the session variable is not registering.
PHP Verion is 5.2.12