I have some code that works on my machine where I do testing and then also on the server that I host them on. I had to re-install the server last weekend because the motherboard crashed. Now whenever I try to send cookies from it, they just don't send. It's the only thing that I can think of as to why my login page doesn't allow the person to login. I think that if it was an SQL problem, it sould have said that my login information was wrong, so I've narrowed it down to the cookies. This does work on my coding machine and had worked before I re-did the server and hadn't changed any of the code since. I've included the code below which can also be found under the login link at http://24.123.93.234/programs/hamradio/index.php . Any help is greatly appreated!
==============CODE BELOW========
<?php
Script 7.1 - login.php
if (isset($_POST['submit'])) { // Handle the form
require_once ('./connect2mysql.php'); // Connect to the db.
// Create a function for escaping the data.
function escape_data ($data) {
global $dbc; // Need the connection.
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
return mysql_real_escape_string($data, $dbc);
} // End of function.
$message = NULL; // Create an empty new variable.
// Check for a username.
if (empty($_POST['username'])) {
$u = FALSE;
$message .= '<p>You forgot to enter your username!</p>';
} else {
$u = escape_data($_POST['username']);
}
// Check for a password.
if (empty($_POST['password'])) {
$p = FALSE;
$message .= '<p>You forgot to enter your password!</p>';
} else {
$p = escape_data($_POST['password']);
}
if ($u && $p) { // If everything's OK.
// Retrieve the user_id and first_name for that username/password combination.
$query = "SELECT login_id, callsign, access_level, assigned_county FROM users WHERE login_id='$u' AND userpass=PASSWORD('$p')";
$result = @mysql_query ($query); // Run the query.
$row = mysql_fetch_array ($result, MYSQL_NUM); // Return a record, if applicable.
if ($row) { // A record was pulled from the database.
// Set the cookies & redirect.
setcookie ('callsign', $row[1], time()+3600, '/', '', 0);
setcookie ('login_id', $row[0], time()+3600, '/', '', 0);
setcookie ('access_level', $row[2], time()+3600, '/', '', 0);
setcookie ('assigned_county', $row[3], time()+3600, '/', '', 0);
header ("Location: [url]http://[/url]" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/loggedin.php");
exit(); // Quit the script.
} else { // No record matched the query.
$message = '<p>The username and password entered do not match those on file.</p>';
}
mysql_close(); // Close the database connection.
} else {
$message .= '<p>Please try again.</p>';
}
} // End of the main Submit conditional.
// Set the page title and include the HTML header.
$page_title = 'Login Page';
include ('include/p_header.inc.php');
// Print the error message if there is one.
if (isset($message)) {
echo '<font color="red">', $message, '</font>';
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset><legend>Enter your information in the form below:</legend>
<p><b>User Name:</b> <input type="text" name="username" size="10" maxlength="20" value="<?php if (isset($POST['username'])) echo $POST['username']; ?>" /></p>
<p><b>Password:</b> <input type="password" name="password" size="20" maxlength="20" /></p>
<div align="center"><input type="submit" name="submit" value="Login" /></div>
</fieldset>
</form><!-- End of Form -->
<?php
include ('include/p_footer.inc.php'); // Include the HTML footer.
?>