Page 1 of 1

Track IP

Posted: Thu May 03, 2012 2:08 pm
by JFMichaud
i just wrote a small code that list IP and some usefull informations on who visit the heldesk page

Code: Select all

 
$f = fopen("ip.html", "a"); 
$log = '<span style="color: #ff0000">IP=</span>' . $_SERVER['REMOTE_ADDR'] . ' <span style="color: #ff0000">Date=</span>';
$log .= date('Y-m-d');
$log .= ' <span style="color: #ff0000">Heure=</span>' . date('H:i:s');
$log .= ' <span style="color: #ff0000">Agent=</span>' . $_SERVER['HTTP_USER_AGENT'] . "\n"; 
fwrite($f, $log);
fwrite($f, '<br /><br />');
fclose($f);
I wonder where is the best place to put that in the hesk code? I've tried in the index.php but it log access too often i just wanna log the first acces of the page index.php where users land

thanks

Re: Track IP

Posted: Fri May 04, 2012 5:53 am
by Klemen
You'll probably want to use sessions.

In index.php delete

Code: Select all

hesk_session_start();
(twice) then add

Code: Select all

hesk_session_start();
just below

Code: Select all

require(HESK_PATH . 'inc/common.inc.php');
Then you can modify your code to check if it's been executed in this session:

Code: Select all

if ( ! isset($_SESSION['logged']))
{
# Your code here
$_SESSION['logged']=true;
}

Re: Track IP

Posted: Fri May 04, 2012 12:08 pm
by JFMichaud
Nice nice...i end up doing this as you said

Code: Select all

/* Get all the required files and functions */
require(HESK_PATH . 'hesk_settings.inc.php');
require(HESK_PATH . 'inc/common.inc.php');
hesk_session_start();

/*TrackIP*/
if ( ! isset($_SESSION['logged']))
{
$f = fopen("ip.html", "a"); 
$log = '<span style="color: #ff0000">IP=</span>' . $_SERVER['REMOTE_ADDR'] . ' <span style="color: #ff0000">Date=</span>';
$log .= date('Y-m-d');
$log .= ' <span style="color: #ff0000">Heure=</span>' . date('H:i:s');
$log .= ' <span style="color: #ff0000">Agent=</span>' . $_SERVER['HTTP_USER_AGENT'] . "\n"; 
fwrite($f, $log);
fwrite($f, '<br /><br />');
fclose($f);
$_SESSION['logged']=true;
}

/* What should we do? */
$action = isset($_REQUEST['a']) ? hesk_input($_REQUEST['a']) : $action='start';

switch ($action)
{
	case 'add':
		
        print_add_ticket();
	    break;

	case 'forgot_tid':
		
        forgot_tid();
	    break;

	default:
		print_start();
}
Thanks it's awesome...