Everything works fine on localhost but when I put it on live server my header is not redirecting after log in and thus session is not being set so my user information is not showing up in the top right corner until I manually refresh the page or navigate to other page. Note that it is not redirecting to any page I put.
header.php:
session_start();
$userid=$_SESSION['userid'];
$username=$_SESSION['username'];
index.php:
include "header.php";
if($username && $userid)
{
echo "You are logged in as <b>$username</b>";
}
else
{
$form="<form action='index.php' method='post'>
<table>
<tr>
<td>Username:</td>
<td><input type='text' name='user'></td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='pass'></td>
</tr>
<tr>
<td><input type='submit' name='submit' value='login'></td>
</tr>
<tr>
<td><a href='register.php'>Register</a></td>
<td><a href='forgotpass.php'>Forgot password?</td>
</tr>
</table>
</form>";
if(isset($_POST['submit']))
{
$user=htmlentities($_POST['user']);
$pass=htmlentities($_POST['pass']);
if($user)
{
if($pass)
{
require 'connect.php';
$pass=md5(md5("123".$pass."456"));
$query=mysqli_query($conn,"SELECT*FROM user WHERE username='$user'");
$numrows=mysqli_num_rows($query);
if($numrows==1)
{
$row=mysqli_fetch_assoc($query);
$dbusername=$row['username'];
$dbid=$row['id'];
$dbpass=$row['password'];
$dbactive=$row['active'];
if($pass==$dbpass)
{
if($dbactive==1)
{
$_SESSION['username']=$dbusername;
$_SESSION['userid']=$dbid;
header("Location:index.php");
}
else
{
echo "You must activate your account.$form";
}
}
else
{
echo "Incorrect password.$form";
}
}
else
{
echo "Incorrect username.$form";
}
mysqli_close($conn);
}
else
{
echo "You must enter password.$form";
}
}
else
{
echo "You must enter username.$form";
}
}
else
{
echo $form;
}
}