Hello,
I have a website that sets a cookie when a user visits the website. The cookie holds an ID number that I have decided to refer to Computer Identification Number (CIN) that is unique for every user. The idea is to be able to identify a computer with the CIN even if the IP changes.
This is the code I use. What it does is that it first checks whether a visitor is an admin. Every admin pc has the admin cookie called 'admin'. If the user is not an admin, the script checks if cookies of the user is enabled and reloads the page to check. If cookies are on, it checks if the user has been here before, by checking if cookie called tp_visitor is set, if it isnt, the script sets a new tp_visitor. The tp_visitor contains the unique ID number {CIN} ). Each visit, the script writes to a database and logs the CIN, IP and timestamp:
Code: <?php
$connection = connect(); //CONNECTS TO MYSQL
if (empty($_COOKIE['admin']) ) { //COMPUTERS WITH COOKIE: 'ADMIN' ARE ADMINS, AND SHOULD NOT BE COUNTED
if (isset($_SERVER['HTTP_REFERER'])) {
$ref = $_SERVER['HTTP_REFERER'];
}
// CHECKS IF USER HAS COOKIE BY FIRST SETTING ONE THEN RELOADING THE SAME PAGE TO CHECK IF THE COOKIE WAS SET
if ( ! isset( $_GET['entry'] ) ) {
setcookie('enabled', 'test', (time() + (60*60*24*365*5)));
header('location: ' . $_SERVER['PHP_SELF'] . '?entry=1&' . SID);
}
else {
//IF COOKIE WAS SET
if (!empty($_COOKIE['enabled'])) {
//IF COOKIE TP_VISITOR IS NOT SET (THE USER IS HERE FOR THE FIRST TIME)
if ( !isset( $_COOKIE['tp_visitor'] ) ) {
$new_cin = 'SELECT COUNT(*) FROM kingoslo.cin';
$resultat = mysql_query($new_cin, $connection);
$new_cin = mysql_result($resultat,0);
$new_cin = $new_cin + 1;
setcookie('tp_visitor', $new_cin, (time() +(60*60*24*365*5)) );
$cookie = 'INSERT INTO kingoslo.cinlog (cin, tid, ip, referanse) VALUES ("' . $new_cin . '", "' . time() . '", "' . getenv("REMOTE_ADDR") . '", "' . $ref . '")';
$new_cin = 'INSERT INTO kingoslo.cin (cin, visits, epost) VALUES ("' . $new_cin . '", 0, 0)';
mysql_query($cookie, $connection);
mysql_query($new_cin, $connection);
}
//IF COOKIE TP_VISITOR IS SET (THE USER IS NOT HERE FOR THE FIRST TIME)
else {
$no_cookie = 'INSERT INTO kingoslo.cinlog (cin, tid, ip, referanse) VALUES ("' . $_COOKIE['tp_visitor'] . '", "' . time() . '", "' . getenv("REMOTE_ADDR") . '", "' . $ref . '")';
mysql_query($no_cookie, $connection);
setcookie('tp_visitor', $_COOKIE['tp_visitor'], (time() +(60*60*24*365*5)) );
}
}
else { //IF COOKIES WAS DISABLED
$no_cookie = 'INSERT INTO kingoslo.cinlog (cin, tid, ip, referanse) VALUES ("COOKIE_DISABLED", "' . time() . '", "' . getenv("REMOTE_ADDR") . '", "' . $ref . '")';
mysql_query($no_cookie, $connection);
}
}
}
close($connection); //CLOSES CONNECTION
?>
Now what is the problem?
Well it seems that when I visit this script, it will sometimes create a new CIN and cookie called tp_visitor even if the user has been on the website before! This seems to happen more frequently when I am directed from different sources, i.e. if I am first directed from a link on Google, then type in the URL of the website in the next attempt.
I was wondering what this may be the result of. I think it is very strange
Thanks
Why do I get this error?
Error:Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/runevid/public_html/Quests/finished_tutorial.php on line
php require help needed
Ok i tried to use the search funtion but the word require is everywhere.i'm really new to creating websites... I've built them in the past but allways had some sort of template to go off of from a
fopen() security
As i understood the usage of fopen() for it to function correctly the Dir you write to has to be rw enabled for the php group, so that fopen() can acces the Dir to write to it. When I try to write
Small problem with image resize script
Hi!I am a little bit new to php and I have an issue installing an image resize script I downloaded (http://shiftingpixel.com/2008/03/03/smart-image-resizer/) and can't seem to get it working.Here's a
file_put_contents and createimagefromjpeg
All,I do somethings and then I have the following code:file_put_contents('./test/'.$filename,$attachment_raw); //Give full path to $filenameI then do:$im = imagecreatefromjpeg($path_to_image_directory
Line break?
Hi, I'm new to the forum and new to php. I'm not sure if I'm using the correct terminology so here it goes. I've created a page with multiple forms that when submitted get emailed to a certain
CU&UC guide
Hi Gurus,
Auto-populating dropdowns and multiple forms.
Here's what I have so far:First drop down = select a state (works)This populates the second drop down (works)Second drop down = select a city (works)This populates the third drop down with local
Need help in log in and log out?
hi there all of u. i have recently created a site for someone. i have placed log in and log out and some links . but those sessions are not working correctly when some one sign in and sign out and
Grabbing Values From an Array for Posting
I have a grid array that I am using with a form that when it hits the currently named test.php it logs in and grabs 3 coordinates (i.e. B1, D3, etc). which come back as XML fields