0

The scenario:

  1. User logging using username & password.
  2. The background getting the credentials and the script will check the the username & password equal to the username & password that are stored in the variables "$username,$pass".
  3. If the username & password doesn't match it won't redirect you to profile.php, if it's matching you will be redirected to profile.php.

The Problems:

  1. When I enter the username & password it's just going to check.php which is the script that will check if the credentials are right or not , so it doesn't redirect me to profile.php

Instead of redirecting to http://localhost/loginpage/profile.php it's going to http://localhost/loginpage/checking.php, with a plank page

enter image description here

  1. I'm not sure if the checking function it's right or not , or if it's really checking

Index.php

<!DOCTYPE html>
<html>
<head>
    <title>Professor Albus Dumbledore Secret Door</title>

    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>

<form class="login-form"  action="checking.php" method="POST">
  <p class="login-text">
    <span class="fa-stack fa-lg">
      <i class="fa fa-circle fa-stack-2x"></i>
      <i class="fa fa-lock fa-stack-1x"></i>
    </span>
  </p>
  <input type="text" class="login-username" autofocus="true" required="true" placeholder="Username" name="username" />
  <input type="password" class="login-password" required="true" placeholder="Password" name="password" />
  <input type="submit" name="login" value="Login" class="login-submit" />
</form>
<a href="#" class="login-forgot-pass">forgot password?</a>
<div class="underlay-photo"></div>
<div class="underlay-black"></div> 

</body>
</html>

checking.php script:

    <?php

$username = "admin";
$pass = "12345";
#$error = array();

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    # code...
    if ($_POST["username"] == $username && $_POST["password"] == $pass) {
        # code...
        header("Location: /profile.php");
        echo "Logged in";
    }


}
?>

Additional Information :

I'm using apache2 server on Ubuntu

  • Typo? Your form action is `checking.php` but your file seems to be `Check.php` – brombeer Aug 25 '20 at 09:03
  • it's my mistake , I wrote it wrong it but in the code and the name of the script is right – maksim lev Aug 25 '20 at 09:08
  • Ok, you might want to [edit] your question and fix that. [Turn on error reporting](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display?rq=1) to see what might go wrong with your code (fyi, `header("Location: /profile.php")` and `echo "Logged in"` are _both_ missing the closing `;` - unless you also typed that wrong) – brombeer Aug 25 '20 at 09:12
  • i edited it , but still the same result – maksim lev Aug 25 '20 at 09:14
  • so instead of redirecting to http://localhost/loginpage/profile.php it's going to http://localhost/loginpage/checking.php – maksim lev Aug 25 '20 at 09:15
  • "_it's going to localhost/loginpage/checking.php_" You should already be on that page. Use an `else` branch to output "debug" data to see if the credentials match. Use "basic" debugging, print out `$_POST["username"]` and `$_POST["password"]` to make sure they are correct. Maybe `trim` your inputs. Good luck – brombeer Aug 25 '20 at 09:19
  • I added the next in checking.php file $u = $_POST["username"]; $p = $_POST["password"]; else{ echo "

    " . $u . "

    "; echo "

    " . $p . "

    "; } the "else" is under the second "if", and this is the results : " . $u . ""; echo " " . $p . " "; } } ?>
    – maksim lev Aug 25 '20 at 09:33
  • Can you maybe [edit] your question and post relevant code there, hard to read in the comments. Maybe `profile.php` redirects you back to `checking.php`? You can use your browser's DevTools->Network tab to see any urls that are being called/redirected – brombeer Aug 25 '20 at 09:41

0 Answers0