Ok, im not having much luck with these sessions, its a lot easier in asp but I would like to understand. I have now created a session and declared a session variable on one page and I am then trying to call it on another but it isnt working for me.
page1 (login page)
<?php
mysql_connect("localhost", "root", "dinosaur") or die(mysql_error());
mysql_select_db("info") or die(mysql_error());
$username = $POST['username'];
$password = $POST['password'];
$result = mysql_query("SELECT * FROM users WHERE username = '$username' && password='$password'");
$row = mysql_fetch_array($result);//the result
if(($row['username'] == $username) && ($row['password'] == $password) && (mysql_numrows($result) == 1))//check username and password
{
session_start();
$_SESSION['name']=$username;
?>
<script language="JavaScript" type="text/javascript">
window.location.replace("home.php");
</script>
<?php
}
elseif (mysql_numrows($result) == 0) {
echo "incorrect login, please retry in 2 seconds ...";
?>
<meta http-equiv="refresh" content="2; URL=login.php">
<?php
}
?>
second page
<?php
if (!isset($SESSION)) {
session_start();
}
echo "hello" . $SESSION["name"];
?>