Hi guys,
I have a problem somewhere in my session or main page code, because when i try to login a user, although it successfully goes through the database, it doesn't write user's first name after the login on the main page. I'm missing something in between. Any help will be appreciated! Thanks and here are the codes that i use:
first_name is user registered name in the database
userid is user's number in the database
<?php
..............................
..............................
$SESSION['first_name'] = $row[1];
$SESSION['userid'] = $row[0];
// Start defining the URL.
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
// Check for a trailing slash.
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
$url = substr ($url, 0, -1); // Chop off the slash.
}
// Add the page.
$url .= '/Index.php';
ob_end_clean(); // Delete the buffer.
header("Location: $url");
exit(); // Quit the script.
} else { // No match was made.
echo '<p><font color="red" size="+1">The user name and the password do not match.</font></p>';
}
} else { // If everything wasn't OK.
echo '<p><font color="red" size="+1">Please try again.</font></p>';
}
mysql_close(); // Close the database connection.
} // End of SUBMIT conditional.
?>
On my main page Index.php file i have:
<?php
echo '<h1>Welcome';
if (isset($SESSION['first_name'])) {
echo ", {$SESSION['first_name']}!";
}
echo '</h1>';
?>