I started learning PHP a couple of days ago, and today I've found my first "hard" problem.
Please consider the following code (simplified):
index.php:
Code: Select all
<?
session_start();
include('global.inc');
if (isset($HTTP_GET_VARSї'login'])) {
include('login.inc');
};
echo $Userї'nick'];
?>Code: Select all
if (!isset($Userї'logged'])) { $Userї'logged'] = FALSE; };
if (!isset($Userї'nick'])) { $Userї'nick'] = 'Stranger'; };So after I submit the form with a username and password, the page is loaded again, this time including the login.inc file:
Code: Select all
<?
$User = DB_GetUser($HTTP_POST_VARSї'user'], $HTTP_POST_VARSї'pwd']);
if ($Userї'logged']) {
$_SESSIONї'User'] = $User;
};
?>['logged'] - TRUE if user and password match, false otherwise
['nick'] - The name of the user, "Stranger" otherwise
So the first time I submit the form, the echo statement in index.php returns the user name from the database, but if I reload the page, by writing http://localhost/index.php, it prints "Stranger" instead of the user name, hence, the $User array is not being saved in the session...
Any help is appreciated!