Location: PHPKode > projects > eBlog > includes/session.php
<?php

/**************************************************************************
 *                                                                        *
 *                                                                        *
 *         Solution: eBlog                                                *
 *          Release: 1.7                                                  *
 *             File: includes/session.php                                 *
 *               By: Emuci inc.                                           *
 *          Website: http://www.emuci.com                                 *
 *        Copyright: (C) 2010 Emcui inc.                                  *
 *                                                                        *
 *                                                                        *
 **************************************************************************
 *                                                                        *
 *                                                                        *
 *   This script is NOT freeware and is subjected to Emuci terms of use   *
 *   located in the docs folder.                                          *
 *                                                                        *
 *                                                                        *
 *************************************************************************/
 
 

include_once 'config.php';

$conn = @mysql_connect($dbhost, $dbuser, $dbpass);
@mysql_select_db($dbname);

if(!$conn){
  die("eBlog is not properly configured. If this is the first run, please <a href=\"install/index.php\">click here</a> to install the script.");
}

$testTable = "eblog_settings";
if(!mysql_num_rows( mysql_query("SHOW TABLES LIKE '".$testTable."'")))
{
  die("eBlog is not properly configured. If this the is first run, please <a href=\"install/index.php\">click here</a> to install the script.");
}




session_start(); 
if (!session_is_registered('permission')) 
{
	session_register('permission');
	session_register('TopicViewed');
	session_register('TopicVisitors');	
	session_register('ip');
	$_SESSION['alerts'] = 0;
	$_SESSION['TotalAlerts'] = 0;
	$_SESSION['permission'] = 0;
	
	
	$query  = "SELECT visitors FROM eblog_settings";
	$result = mysql_query($query);
	while($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{
		$totalVisitors = $row['visitors'];
	}
	$totalVisitors++;
	$sql0="UPDATE eblog_settings SET visitors='$totalVisitors' WHERE id = '1'";
	$result=mysql_query($sql0);
}


$ip = "";
if (!empty($_SERVER['HTTP_CLIENT_IP']))
{
	$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
{
	$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
	$ip=$_SERVER['REMOTE_ADDR'];
}
$_SESSION['ip'] = $ip;


// WHO'S ONLINE
$pageName = $_SERVER["SCRIPT_NAME"];

$session=session_id();
$time=time();
$time_check=$time-600;

$result = mysql_query("SELECT * FROM eblog_online", $conn);
$count_user_online = mysql_num_rows($result);

$result = mysql_query("SELECT * FROM eblog_online WHERE ip = '$ip'");	
$row = mysql_fetch_row($result);
$dbID = $row[0];
if(empty($dbID))
{
	$sql1="INSERT INTO eblog_online(ip, name, page, timeout)VALUES('$ip','$session', '$pageName', '$time')";
	$result1=mysql_query($sql1);
}
else 
{
	$sql2="UPDATE eblog_online SET timeout='$time' WHERE name = '$session'";
	$result2=mysql_query($sql2);
	$sql2="UPDATE eblog_online SET page='$pageName' WHERE name = '$session'";
	$result2=mysql_query($sql2);	
}

$sql4="DELETE FROM eblog_online WHERE timeout<$time_check";
$result4=mysql_query($sql4);


mysql_close($conn);	

?>
Return current item: eBlog