Menu
If I have search form and track users with session, can be added session function and store this into database=
Is this correct way to track all searches from particular users (logged in or logged out).
[code=php]
session_start();
$_SESSION[‘id’] = $_SERVER[‘REMOTE_ADDR’];
Names are now known sometimes and I pull those values for particular IP address…
[code=php]
<?php
$cookieData = //read cookie data
array_push($cookieData, $_SERVER['PHP_SELF']);
?>
[/code]
[code=php]
session_start();
setcookie('search','cusearch',time()+60*60*24*7);
[/code]
Is correct setting cookie?
[code=php]
session_start();
setcookie('search','cusearch',time()+60*60*24*7);
[/code]
How to add to database this user if he returns after 5 days?[/QUOTE]
[code=php]<?php
//okay so lets check if the cookie exists and has a numeric value
if(isset($_COOKIE['tracker'])) && (is_numeric($_COOKIE['tracker']))){
//lets now check if its older then five days
if($_COOKIE['tracker'] <= time()-(3600*24*5)){
//ok its older then 5 five days lets insert
//insert into DB here
}
}
//get the current unixstamp
$visitDate = time();
//set cookie for 31days
cookie('tracker', $visitDate, time()+3600*24*31, '/');
?>[/code]
[code=php]session_start();
$_SESSION['id'] = $_SERVER['REMOTE_ADDR']; [/code]
[code=php]
session_start();
[/code]
It will not work if they refuse the cookie. IP address has nothing to do with it, it's about the session_ID they store in the cookie. I refuse most cookies, they're mostly for advertisers and google. So plan on having people refuse them.[/QUOTE]
[code=php]
$visitDate = time();
cookie('cutracker', $visitDate, time()+3600*24*30, '/'); //set cookie for 30days
if(isset($_COOKIE['cutracker'])) && (is_numeric($_COOKIE['cutracker']))){
//lets now check if its older then 30 days
if($_COOKIE['cutracker'] <= time()-(3600*24*30)){
//ok its older then 30 five days lets insert
//insert into DB here
}
}
[/code]
Is this correct?
1. How you set sessions and extend the session time up to 30 days?
Is not session only one time for visit?2. How to store into db values for cookie as you posted value: $visitDate
If you have more visitors it will be the same value for cookie?
[code=php]
[/QUOTE]
$visitDate = time();
cookie('cutracker', $visitDate, time()+3600*24*30, '/'); //set cookie for 30days
if(isset($_COOKIE['cutracker'])) && (is_numeric($_COOKIE['cutracker']))){
//lets now check if its older then 30 days
if($_COOKIE['cutracker'] <= time()-(3600*24*30)){
//ok its older then 30 five days lets insert
//insert into DB here
}
}
[/code]
[code=php]
if(isset($_COOKIE['cutracker']) && (is_numeric($_COOKIE['cutracker']))) //if the cookie exists and has a numeric value
{
if($_COOKIE['cutracker'] <= time()-(3600*24*30)) //check if its older then 30 days
{
$cur_cookie = $_COOKIE['cutracker'];
$i=0; // start counter
$keytofind = 1; // the position we want to find the key for $key = ''; // the key
foreach($_GET as $k => $v){
if($i == $keytofind){$key = $k;}
$i++;
}
$ststring = $_GET[q]; // Store only search queries
$sql = "INSERT INTO tbl_searchterms (id
,cur_cookie
,cur_timestamp
,cur_datetime
,key
,ststring
,stip
) ";
$sql .= "VALUES ('','$cur_cookie','$cur_timestamp','$cur_datetime', '$key', '$ststring','$ip_address')";
$rs = mysql_query($sql) or die(mysql_error());
mysql_close();
}
}
if (!isset($_COOKIE['cutracker']))
{
$visitDate = time(); //get the current unixstamp
cookie('cutracker', $visitDate, time()+3600*24*30, '/');//set cookie for 30 days
$i=0; // start counter
$keytofind = 1; // the position we want to find the key for $key = ''; // the key
foreach($_GET as $k => $v){
if($i == $keytofind){$key = $k;}
$i++;
}
$ststring = $_GET[q]; // Store only search queries
$sql = "INSERT INTO tbl_searchterms (id
,cur_cookie
,cur_timestamp
,cur_datetime
,key
,ststring
,stip
) ";
$sql .= "VALUES ('','','$cur_timestamp','$cur_datetime', '$key', '$ststring','$ip_address')";
$rs = mysql_query($sql) or die(mysql_error());
mysql_close();
}
?>
[/code]
0.1.9 — BETA 5.20