0

I made a webapplication with login. Based on the role it should go to a indexpage in a different folder depending on the role the user has. On my local machine (with the use of MAMP Pro) it works perfectly, but when i copy the whole folder to my hosting (with the right connection to the database in my hosting) it will show that a user is logged on, but doesn't redirect to the folders. the Header comes within the Session_start() storage.

<?php

define("TITLE1", "Inlog"); 
session_start();

include('includes/header.php'); 
if( isset( $_POST['login'] ) ) {
    $formUser = validateFormData( $_POST['username'] );
    $formPass = validateFormData( $_POST['password'] );
    $query = "SELECT * FROM `werknemers` WHERE `username`='$formUser'";
    $result = mysqli_query( $link, $query );
    if( mysqli_num_rows($result) > 0 ) {
        while( $row = mysqli_fetch_assoc($result) ) {
            $id = $row['werknemerid'];
            $user       = $row['username'];
            $email      = $row['email'];
            $hashedPass = $row['password'];
            $role = $row['role'];
        }
        if( password_verify( $formPass, $hashedPass ) ) {
            session_start();
            $_SESSION['loggedInUser'] = $user;
            $_SESSION['loggedInEmail'] = $email;
            $_SESSION['loggedInRole'] = $role; 
            $_SESSION['loggedInID'] = $id;
            if($role == 'planner'){
                header('location: planner/indexplanner.php');
                exit();
            }  else if($role == 'werknemer'){
                header('location:werknemer/indexwn.php');
                exit();
            }
        } else {
            $loginError = "<div class='alert alert-danger'>Wrong username / password combination. Try again.</div>";
        }
    } else {
        $loginError = "<div class='alert alert-danger'>No such user in database. Please try again. <a class='close' data-dismiss='alert'>&times;</a></div>";
    }
    mysqli_close($link);
}

?>
<div class="container">
    <div class="row">
        <div class="col-md-2"></div>
        <div class="col-md-8">
            <h1>Login</h1>
            <p>Use this form to log in to your account</p>
            <?php echo $loginError; ?>
            <form class="form-inline" action="<?php echo htmlspecialchars( $_SERVER['PHP_SELF'] ); ?>" method="post">
                <div class="form-group">
                    <label for="login-username" class="sr-only">Username</label>
                    <input type="text" class="form-control" id="login-username" placeholder="username" name="username">
                </div>
                <div class="form-group">
                    <label for="login-password" class="sr-only">Password</label>
                    <input type="password" class="form-control" id="login-password" placeholder="password" name="password">
                </div>
                <button type="submit" class="btn btn-default" name="login">Login!</button>
            </form>
            <br>
            <br>
        </div>
        <div class="col-md-2"></div>
    </div>
</div><br>
<br>
<br>
<?php include('includes/footer.php'); ?>
Scoots
  • 3,048
  • 2
  • 21
  • 33
  • 3
    Have you tried step by step debugging? Dumping values? Making sure each part of the script actually runs as it should do? Have you got any errors? Are errors even turned on? What have you tried to fix this issue? – ProEvilz Oct 20 '17 at 15:12
  • Also: code formatting, SQL injection – mario Oct 20 '17 at 15:13
  • Please indent your code properly. It will make it easier for both us and you to actually follow the flow and spot potential mistakes. – M. Eriksson Oct 20 '17 at 15:14
  • I build it step by step, checking the workings and all. It works perfectly on my local webserver. But on my hosting server it does not. That is why i cannot figure out why. – Gitte Bolster Oct 20 '17 at 15:20
  • Did you activate error reporting and/or have you checked your error logs?! – deceze Oct 20 '17 at 15:39
  • I did Deceze. I found a workaround. Not one i'm proud of, but it workes. Took me just 13 days to find the solution. – Gitte Bolster Oct 20 '17 at 20:01

0 Answers0