When a user logs in, a session starts, containing the ID assigned to them upon registration. When I try an print that page in “home.php”, it doesn’t show up. Any help?
This is all the code before it assigns the session variable.
<?php
require("includes/connect.php");
require("includes/redirect.php");
$resultUser = mysql_query(
sprintf(
"SELECT Username FROM sq_users WHERE Username = '%s'",
mysql_real_escape_string($_POST['username'])
)
);
if(0 !== mysql_num_rows($resultUser)){
$resultUser = mysql_query(
sprintf(
"SELECT ID,Username,Passwd FROM sq_users WHERE Username = '%s'",
mysql_real_escape_string($_POST['username'])
)
);
$passFlat = $_POST['passwd'];
$pass = md5($passFlat);
$row = mysql_fetch_row($resultUser);
if($pass == $row[2]){
session_start();
$_SESSION['id'] = $row[0];
header('Location: '. $root . $home);
mysql_close($con);
exit;
}
This is the “home.php” code.
<?php
echo "User ID = ". $_SESSION['id'];
?>