How to get visitor track ?

<?php

//Calculate 60 days in the future
//seconds * minutes * hours * days + current time

$inTwoMonths = 60 * 60 * 24 * 60 + time();
setcookie(‘lastVisit’, date(“G:i – m/d/y”), $inTwoMonths);

if(isset($_COOKIE[‘lastVisit’]))

{
$visit = $_COOKIE[‘lastVisit’];

}
else

{

echo “You’ve got some stale cookies!”;

}
echo “Your last visit was – “. $visit;
?>

Advertisements

2 thoughts on “How to get visitor track ?

  1. Nice one…
    But why to occupy memory by declaring a variable?
    You have done the same like:

    $inTwoMonths = 60 * 60 * 24 * 60 + time();
    setcookie(‘lastVisit’, date(“G:i – m/d/y”), $inTwoMonths);

    You can also do like:

    setcookie(‘lastVisit’, date(“G:i – m/d/y”), 60 * 60 * 24 * 60 + time());

    And for:

    if(isset($_COOKIE[‘lastVisit’]))
    {
    $visit = $_COOKIE[‘lastVisit’];
    }
    else
    {
    echo “You’ve got some stale cookies!”;
    }
    echo “Your last visit was – “. $visit;

    You can also do like:

    echo (isset($_COOKIE[‘lastVisit’])) ? (“Your last visit was – “.$_COOKIE[‘lastVisit’]) : (“You’ve got some stale cookies!”;)

    Njoy.. 😉

    Like

I like to hear from you about this !!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s