Info: Server Linux, PHP 4.0.6, register global on
I can't figure out whether my login page is not passing the the sessions and or cookie or if there is a problem with the logged in page syntax. Now this runs fine on my local server which runs PHP 4.3.1 but not on my web server (4.0.6). I have omiteed the HTML portions of the pages. Now when I log in, I get redirected to the logged in page but then my header redirect takes me back to the login page which means to me that logged in page did not get the cookie.
I did some searching and most of the links that may a have a promising answer are broken (must be because my issue concerns such a old version of PHP) Unforntately I'm still too new to the language to see the obvious mistake, so any help would be apprieciated.
Login Page:
<?php
if (isset($submit)) {
require_once ('../../db.php'); // Connect to the db.
function escape_data ($data) {
global $dbc;
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
return mysql_escape_string($data);
} // End of function.
$message = NULL;
if (empty($username)) {
$u = FALSE;
$message .= '<p>You forgot to enter your username!</p>';
} else {
$u = escape_data($username);
}
if (empty($password)) {
$p = FALSE;
$message .= '<p>You forgot to enter your password!</p>';
} else {
$p = escape_data($password);
}
if ($u && $p) {
$query = "SELECT user_id, first_name FROM users WHERE username='$u' AND password='$p'";
$result = @mysql_query ($query); // Run the query.
$row = mysql_fetch_array($result, MYSQL_NUM);
if ($row) {
// Set the cookies & redirect.
session_name ('samples');
session_set_cookie_params (900, '/users/', 'mysite');
session_start();
$HTTP_SESSION_VARS['first_name'] = $row[1];
$HTTP_SESSION_VARS['user_id'] = $row[0];
header ("Location: http://" . $HTTP_SERVER_VARS['HTTP_HOST'] . dirname($HTTP_SERVER_VARS['PHP_SELF']) . "/view_registered.php");
exit(); // Quit the script.
} else { // No record matched the query.
$message = '<p>The username and password entered did not match those on file.</p>';
}
mysql_close(); // Close the database connection.
} else {
$message .='<p>Please try again.</p>';
}
}
?>
Logged In Page:
<?php
session_name ('samples');
session_start(); // Start the session.
if (!isset($HTTP_SESSION_VARS['first_name'])) {
header ("Location: http://" . $HTTP_SERVER_VARS['HTTP_HOST'] . dirname($HTTP_SERVER_VARS['PHP_SELF']) . "/index.php");
exit(); // Quit the script.
}
?>