I have a login script that checks user credentials against a database, and if they are correct will assign them a session then forward them to the home screen.
For some reason, it will not forward, but will happily output text that appears after it should have read the forwarding code.
<?php
//require_once('scripts/include.php');
require_once('scripts/includePDO.php');
$error = '';
$form = $_POST['submit'];
$email = $_POST['email'];
$password = $_POST['password'];
if( isset($form) ) {
if( isset($email) && isset($password) && $email !== '' && $password !== '' ) {
$sql = "SELECT * FROM tbl_users WHERE email = :email and password = :password";
$q = $conn->prepare($sql);
$q->bindValue(':email',$email,PDO::PARAM_STR);
$q->bindValue(':password',$password,PDO::PARAM_STR);
$q->execute();
$r = $q->fetch(PDO::FETCH_ASSOC);
if(($r)!=0)
{ //success
$answer = $r['id'];
$_SESSION['logged-in'] = true;
$_SESSION['who'] = $answer;
echo "This text echos no probelm";
//If the login details are entered and they match those in the database, forward to new page.
header('Location: home/');
echo "Even this text will be shown";
exit;
// If information is wrong or missing, provide error message.
} else { echo "Sorry, something hasn't worked. Are you entering all the information correctly?"; }
}
}
?>