This code works online for login. I wonder it doesn't work offline for login. I am using windows 7 and apache server. I already enter the correct username and password. It shows nothing as if nothing happens.


/* the files */

// username and password sent from form

// To protect MySQL injection (more detail about MySQL injection)
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);

$encrypted_password = md5($password);

$sql = "SELECT * FROM user WHERE username='$username' and password='$encrypted_password'" or die(mysql_query);

// Mysql_num_row is counting table row

echo $count; 
// If result matched $username and $password, table row must be 1 row

if ($count==1){

// Register $myusername, $mypassword and redirect to file "login_success.php"

$_SESSION['username'] = $username;
$_SESSION['password'] = $password;

else {
echo "Wrong Username or Password";

Edited by davy_yg

4 Years
Discussion Span
Last Post by TonyG_cyprus

What do you mean by offline? Are database and webserver accessible when you are offline (localhost) or are they somewhere else (accessible through internet)? Do you have php.ini set up to display errors? Do you have a ob_end_flush() command at the end?

Edited by broj1


I think you are saying about offline server on localhost. Then that won't work (e.g. setting the APACHE server to offline) it won't work


by the way he said, I think he is trying to test the code and it was working on the Internet host but not under something like xampp which is using the localhost.

if not then, the offline is really mean that he shut down the apache...

one thing I notice is you are using $_SESSION and you didnt have session_start();

my suggestion is try to comment out line 38 and put a session_start(); at the top and then put a echo $_SESSION['username']; below line 38.


Like broj1 says, if you don't have ob_end_flush() at the last line the script is just hanging, waiting for the starting gun.
And as yy886 says

comment out line 38 and put a session_start(); at the top and then put a echo $_SESSION['username']; below line 38.

don't do any redirects until you know the script is working,= basic debugging.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.