Ok so I asked this question before and got a lot of good answers unfortunately none of them changed the outcome. I'm trying to redirect after a 'login' page on the site I'm working on. I'm gathering the id in a session and trying to redirect. This works fine in a lot of the sites I use, the one difference with this site is that it doesn't use localhost, it has a server name. At first I had an echpo before the header and everyone told me that was the problem, I removed it to fix it but nothing changed. Here's the code:
<?php
/*set all the variables*/
$email = $_POST['email'];
$password = sha1($_POST['password']); /* hash the password*/
$conn = mysqli_connect ('servername', 'username', 'password', 'databasename') or die('Error connecting to MySQL server');
/*select the id from the users table that match the conditions*/
$sql = "SELECT id FROM users WHERE email = '$email' AND password = '$password'";
$result = mysqli_query($conn, $sql) or die('Error querying database.');
$count = mysqli_num_rows($result);
if ($count == 1) {
$row = mysqli_fetch_array($result);
session_start();
$_SESSION['user_id'] = $row['id'];
/*If true head over to the users table*/
header('location: users_table.php');
}
/*If invalid prompt them to adjust the previous entry*/
else {
echo '<h2>Invalid Login</h2><br />';
echo '<h2>Click <a href="javascript:history.go(-1)">HERE</a> to go back and adjust your entry.</h2>';
}
mysqli_close($conn);
?>
The only other code on the page are the HTML HEAD and BODY tags. I've even asked one of my old college teachers for help and he said the code looks fine, he can't find the problem. so I'm asking again. Is there maybe a way I can use an HTML or SCRIPT redirect and stay in the session?
Thanks