1

I'm having a problem with redirecting a page in php.

<?php           
        include '../include/dbfunctions.php';
        $email = $password = "";
        $err = "";
        if ($_SERVER["REQUEST_METHOD"] == "POST") {
            if (isset($_POST['login']) && !empty($_POST['password'])) {

                $email = trim($_POST['email']);
                $password = trim($_POST['password']);

                $link = get_db_connection();


                if (mysqli_connect_errno()) {
                    die(" Something went wrong ! ");
                }

                $user_email = mysqli_real_escape_string($link, $email);
                $user_password = mysqli_real_escape_string($link, $password);

                $query = "SELECT  username FROM user WHERE user_email = '$user_email' AND user_password = SHA1('$user_password') AND user_active = '1';";
                $data = mysqli_query($link, $query);

                if (mysqli_num_rows($data) == 1) {

                    $row = mysqli_fetch_array($data);

                    $username = $row['username'];
                    mysqli_close($link);
                    if (!empty($username)) {

                        header('location:http://www.xxxxxxxxxxxxxx.be/login/dashboard.php');
                        exit();
                    }
                } else {
                    $err = "Invalid combination of e-mail and password";
                    echo $err;
                }
            } else {

            }
        }
        ?>

I can't figure it out. If i fill in an invalid password or email, i get the error message. But when they are correct, nothing happens.

Ace
  • 31
  • 9
  • is it because you are using lowercase 'l' in location as it is `header('Location:...`. If no, what url you are getting in the browser ? – jitendrapurohit Oct 08 '15 at 06:29
  • First check before header nothing is echo and use `Location:` like this. – Kausha Mehta Oct 08 '15 at 06:31
  • Funny thing is that it works fine in Netbeans but no online??? – Ace Oct 08 '15 at 06:35
  • the url doesn't change. – Ace Oct 08 '15 at 06:36
  • is it working with the uppercase 'L' in Location ? – jitendrapurohit Oct 08 '15 at 06:36
  • Turn on error reporting at the top of your script - `ini_set('display_errors', 1); error_reporting(-1);`. I suspect you have a "Headers already sent" error.. Also, the syntax is `header("Location: http://www.....");`. Could you also show your form html. You might not be processing anything.. – Darren Oct 08 '15 at 06:55

2 Answers2

0
if (!empty($username)) {
              header('location:http://www.xxxxxxxxxxxxxx.be/login/dashboard.php');
                    exit();}

$username might be empty.

Anders
  • 8,307
  • 9
  • 56
  • 88
Jitendra Kumar. Balla
  • 1,173
  • 1
  • 9
  • 15
0
if (!empty($username)) {
     header('location:http://www.yoursite.be/login/dashboard.php?error=error in login please try agine');
     exit();
}
Jazi
  • 6,569
  • 13
  • 60
  • 92