Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create visitor unique ID?

Tags:

javascript

php

I plan to create visitor unique ID and named as log file, as existing now I use the IP visitor as log file name i.e. logs/127.0.0.1.php but I think this is not enough because some visitor using share an IP address for PC's.

The visitor log file itself as setting place of configuration of visitors itself, so I plan to add another unique ID to identify each different visitor so let's say the log file: logs/127.0.0.0.1-t3451dq.php, -t3451dq as unique ID so as long as visitor browsing on my website the unique log file as setting configuration for each user (because I use plain text)

Currently I use:

<?
$filename = "./logs/".$_SERVER['REMOTE_ADDR'].".php" ; //out put logs/127.0.0.1.php
$data stripcslashes($data);
// each Visitor configuration here...
// bla...bla...

/* Writing file configurations */
    $buat = fopen($filename, "w+");
    fwrite($buat, "$data");
    fclose($buat);
?>

so I need $filename add the $unique ID as name of their log file. Any ideas how to do that?

like image 950
jones Avatar asked Dec 08 '09 09:12

jones


People also ask

What is a visitor ID?

The visitor ID is a random and unique value generated when a user visits the search site for the first time.

What is a visitors badge?

Visitor badges are commonly issued by businesses and institutions (e.g., educational, governmental) to easily identify visitors and control and monitor access to areas/systems not open to the public. All visitors should be issued a visitor badge.

What is the purpose of a visitors card?

Its main purpose is to create an identity of the visitor to help manage security access. During the check-in process, a visitor pass can be printed for visitors to wear for identification purposes during their visit.


1 Answers

Try uniqid.

You can store this unique ID in the users session or in a cookie.

Example (not tested)

session_start();
if(!isset($_SESSION['uniqueID']))
{
    $_SESSION['uniqueID'] = uniqid();
}
$filename = "./logs/".$_SESSION['uniqueID'].$_SERVER['REMOTE_ADDR'].".php" ;

Using a session will mean that if the same user closes their browser (or the session expires) they will get a new ID, which may or may not be what you want.

If you want a more persistent tracker then you may be better using cookies, and store the ID in the cookie (create a new ID if no cookie exists).

if(!isset($_COOKIE['uniqueID']))
{
    $expire=time()+60*60*24*30;//however long you want
    setcookie('uniqueID', uniqid(), $expire);
}
$filename = "./logs/".$_COOKIE['uniqueID'].$_SERVER['REMOTE_ADDR'].".php" ;

If you cannot use cookies/session then you may need to pass around the ID in your URL query string e.g. mypage.php?id=35dfgdfg3434

like image 109
row1 Avatar answered Sep 30 '22 13:09

row1