Jump to content

Stupid $_SESSION Problem


Azaz

Recommended Posts

 

 

So like When somones enter my site it shows them as a guest, but then if they havn't clicked anywere for about 5minutes and then refresh or if somone else refresh it will delete from the active users list because it's been over 5 minutes, but then if that same person refreshes again my script wont catch them as a GUEST AGAIN!! It just shows no one online, none of my if's catch him and put him in the ibf_session table! :(

 

 

//check for cookies
//If no username, Is a Guest, Has COOKIE_ID and cookie USER_NAME and COOKIe PASSWORD
if(!isset($_SESSION['user_name']) && !isset($_SESSION['is_guest']) &&
isset($_COOKIE['user_id']) && isset($_COOKIE['user_name']) && isset($_COOKIE['password'])){
$user_cond = "user_name='{$_COOKIE['user_name']}'";

$sql = "SELECT `id`,`user_name`,`approved` FROM users WHERE 
           $user_cond
		AND `pwd` = '{$_COOKIE['password']}' AND `banned` = '0'
		"; 
$result = mysql_query($sql) or die (mysql_error()); 
$num = mysql_num_rows($result);
  // Match row found with more than 1 results  - the user is authenticated. 
    if ( $num > 0 ) { 
list($id,$full_name,$approved) = mysql_fetch_row($result);	
if(!$approved) {
echo "YOU FREAKING HACKER";
 exit();
 }
	$_SESSION['user_id']= $id;  
	$_SESSION['user_name'] = $full_name;
	$lol = session_id();
 //$minute5 = 30 ? (time() - 30) : (time() - 3600);
           // mysql_query("DELETE FROM ibf_sessions WHERE running_time < {$minute5}");
mysql_query("INSERT INTO ibf_sessions (id, member_name, member_id, ip_address, running_time, location, member_group) ".
                       "VALUES ('".$lol."', '{$_SESSION['user_name']}', '{$_SESSION['user_id']}', '{$_SERVER['REMOTE_ADDR']}', '".time()."', ".
                       "'Index', '1')") or die(mysql_error());
	unset($_SESSION['is_guest']);
   }
}
$lol = session_id();
//Thanks
if (!$id) { //Create Guest Session ~
if (!isset($_SESSION['user_id']) && @(!$_SESSION['is_guest']) && !isset($_COOKIE['password'])) {
//$minute5 = 39 ? (time() - 30) : (time() - 3600);
//echo $minute5;
           // mysql_query("DELETE FROM ibf_sessions WHERE running_time < {$minute5}");

mysql_query("INSERT INTO ibf_sessions (id, member_name, member_id, ip_address, running_time, location, member_group) ".
                       "VALUES ('".$lol."', 'Guest', '0', '{$_SERVER['REMOTE_ADDR']}', '".time()."', ".
                       "'Index', '0')") or die(mysql_error());
    $_SESSION['is_guest'] = 'yes';
}
}
if (isset($_SESSION['user_id']) && !isset($_SESSION['is_guest'])) {
mysql_query("UPDATE ibf_sessions SET member_name='{$_SESSION['user_name']}',member_id='{$_SESSION['user_id']}',member_group='1', running_time='".time()."', in_forum='".$f."', in_topic='".$topicid."', location='".$act."' WHERE id='".$lol."'") or die(mysql_error());
  }
else {
mysql_query("UPDATE ibf_sessions SET member_name='Guest',member_id='0',member_group='0', running_time='".time()."', in_forum='".$f."', in_topic='".$topicid."', location='".$act."' WHERE id='".$lol."'") or die(mysql_error());


}

 

 

Thanks, it might be confusing but re read :D

Link to comment
https://forums.phpfreaks.com/topic/209163-stupid-_session-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.