My file below checks if the user is ! logged in, and redirects to login page, or does nothing if user is logged in.
<?php
if(isset($_COOKIE['SID']))
{
$sid= $_COOKIE['SID'];
$uid = $_COOKIE['User'];
$lastip = $_COOKIE['Cname'];
$_POST['SID']=$sid;
$check = mysql_query("SELECT * FROM users WHERE SID = '".$_POST['SID']."'")or die(mysql_error());
while($info = mysql_fetch_array( $check )) {
if ($uid != md5($info['id'])) {include 'inc/php/endsession.php'; }
if ($lastip != $info['LastIP']) {include 'inc/php/endsession.php'; }
}
include'inc/php/gettime1.php';
}
else
{
header( 'Location: login.php' ) ;
}
?>
My problem is how to redirect to login.php if the cookie SID is set, but contains invalid data that does not exist in my database instead of calling mysql_error().