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'>×</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'); ?>