1

I am experiencing very difficult (hard to find) problem with my PHP login script. I am using sessions to make login work with standard send form and using this script:

public function login($user, $password)
    if (!empty($user) && !empty($password))
    {    
      $user = $web->esc($user);
      $password = $web->Hash($user, $password);

      $db->selectDb('login');
      $qw = mysql_query("SELECT * FROM account WHERE username='".$user."' AND pass='".$password."'");

      if (mysql_num_rows($qw) > 0)      
      {    
        $result = mysql_fetch_array($qw);
        $_SESSION['user_name'] = $result['username'];
        $_SESSION['user_id'] = $result['id'];  
        return true; 
...
...

And in login I am using something like this:

if(isset($_POST["send"]))
{
  if($auth->login($_POST["name"], $_POST["pass"]))
  {
    header("location: ./");  
  }
}
else         
...
...

It is working quite ok but in Opera and sometimes other browsers there is a problem. When I log in in Opera, Google Chrome etc for example - fill in my form and send it - it just "stucks" on login form and never let me see my page after login - it is working in other browsers - I just do not see the problem why in some browsers it is not wokring. DO you have any idea how to fix this? Thank you.

5
  • Not completely related with the question but I hope you escaped $user and $password inputs (to prevent SQL injection). Commented May 26, 2012 at 10:20
  • Like how escaped? ... Problem is that ater login there is still "login form" instead new page in "header("location: ./");" which is different after login. Commented May 26, 2012 at 10:22
  • Sorry, I didn't notice the $web->esc part. Anyway, have you tried putting a return; after header('location:./');. I had some troubles with it sometimes, too. Commented May 26, 2012 at 10:26
  • where is $web initialised? It doesn't appear to be in scope do you mean $this->web Commented May 26, 2012 at 10:40
  • Seems it is working only sometimes this return code ... Commented May 26, 2012 at 17:10

3 Answers 3

1

After an header location: you have to be sure that PHP will no send data. So try to put the function exit(); just after the header function.

Sign up to request clarification or add additional context in comments.

1 Comment

So exit really works thank you :) Just needed to delete cache after it.
1

Activate error reporting and display errors.

error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('scream.enabled', TRUE);

It should show you a "Warning headers already sent in file file on line line".

It would be preferable if you wrote the error reporting statements somewhere inside the first index.php file and the code was included by your index. Because parse errors in the current file aren't shown it just gives you a white screen.

Comments

1

OK problem solved after having these errors:

Warning: Unknown: open(/var/lib/php5/sess_5019088d181146779ffc848a095c27ff, O_RDWR) failed: No space left on device (28) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php5) in Unknown on line 0

In settings in php.ini changing this:

session.save_path = /tmp

Everything works fine thx to Mihai Stancu for error analysis code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.