0

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().

Edited by Brianbc: Email notification

4
Contributors
9
Replies
15
Views
6 Years
Discussion Span
Last Post by theonly
0

Ok try this instead of assigning $sid to $_POST just leave it as $sid.

Then use this code

if(mysql_num_rows($check) == 0){
   header("Location: whatever.php");
}

Edited by theonly: n/a

0

It works! :) :-D

$check = mysql_query("SELECT * FROM users WHERE SID = '$sid'");
      if(mysql_num_rows($check) == 0){
      header('Location: http://www.eguard.comli.com/theme2/login.php');
      }

:) Thanks everyone! 8)

Human eyes have no capacity to discern greatness while it abides with them.

0

Just for your knowledge. The reason why

if(!$check)

Does not work is because MySql will return a 0 after you make the select call, hence $check will exists.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.