Track IP

Everything related to Hesk - helpdesk software

Moderator: mkoch227

Post Reply
JFMichaud
Posts: 9
Joined: Fri Apr 20, 2012 12:06 pm

Track IP

Post 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
Klemen
Site Admin
Posts: 10136
Joined: Fri Feb 11, 2005 4:04 pm

Re: Track IP

Post 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;
}
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
JFMichaud
Posts: 9
Joined: Fri Apr 20, 2012 12:06 pm

Re: Track IP

Post 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...
Post Reply