PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hi everyone, I am pretty new to php, so forgive any foolish mistakes! The code below is for a simple login/authentication script, works fine in Netscape and Firefox, but no joy in Explorer 5.5 or 6 . PHP version is 4.4.1 .
<?php
session_start();
if (isset($_POST['submit2'])) {
// Check if the form has been submitted.
ob_start();
require_once ('mysql_connect.php'); // Connect to the database.
if (empty($_POST['username'])) { // Validate the username.
$u = FALSE;
} else {
$u = escape_data($_POST['username']);
}
if (empty($_POST['password'])) { // Validate the password.
$p = FALSE;
} else {
$p = escape_data($_POST['password']);
}
if ($u && $p) { // If everything's OK.
// Query the database.
//first get the date of registration from the database
$query = "SELECT username, first_name,registration_date,term FROM users WHERE username='$u' AND password=PASSWORD('$p')";
$result = @mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_ASSOC);
if ($row) { // A match was made. The next few lines check that the registration has not expired
if ($row[term] == 'six') {$interval = 6;} else {$interval = 12;}
$query = "SELECT PERIOD_DIFF(now(),registration_date) WHERE username='$u' AND password=PASSWORD('$p')";
$result = @mysql_query ($query);
if ($result < $interval) {
// Start the session, register the values & redirect.
$_SESSION['first_name'] = $row['first_name'];
$_SESSION['username'] = $row['username'];
ob_end_clean(); // delete the buffer
header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/index.php");
exit();
}
else { header ("Location:reg_expired.php");exit();}
}
mysql_close(); // Close the database connection.
} else { // If everything wasn't OK, finsish the session
$_SESSION['username'] = NULL;
$_SESSION['first_name'] = NULL;
unset($_SESSION['username']);
unset($_SESSION['first_name']);
}
} // End of SUBMIT conditional.
ob_end_flush();
?>
I have tried turning on error reporting and that cleared up a few little bugs, but IE is still not playing nicely. I hit the login button and it should either come up with an error or else it should log you in - which works in netscape.
In explorer it just reloads the page - no data appears to be transferred between pageloads?
any help appreciated!
anthony
I think I may have found the problem - I found this on another forum, let me know if it's right or not:
"Quick point, since this had been going round in circles for days...
IE will not accept sessions from a domain that has an non alpha-numeric character in it. My development site was running under the vhost mos_dev and it was killing me, trying to work out why IE kept dropping my sessions."
My url is: http://preview.hosts.co.uk/~londonmanag ... /index.php
so I think maybe the squiggle is causing this? Thanks for your quick reply Maugrim, not sure I understand your suggestion, could you pretend I am really thick ( you won't have to try too hard!!) and explain it a bit more?
cheers!
anthony
i've also noticed weird weird weird behavior in I.E. if you don't open and close your HTML tags properly. so double check your source from I.E. (firefox tends to fix your screw ups oddly enough, I.E. just says screw you:) )
yeah, I have noticed this too - the page validates in dreamweaver 8, and I can't see anything else wrong with it. We are moving the site to a different url later, so I will be keeping my fingers crossed!
anthony