...

View Full Version : User Last visited script help



paffley
01-07-2012, 12:23 AM
I have this piece of code but its not working for me and cannot find the answer as im currently learning php...

the code should show when I/user last visited the website with a cookie set, heres what i have...


<?php

if(isset($_COOKIE['LastVisit']))

{
$last = $_COOKIE['LastVisit'];

}

$year = 31536000 + time() ;

setcookie(LastVisit, time (), $year) ;

if (isset ($last))
{
$change = time () - $last;
if ( $change > 86400)
{
echo "Last visit was". date("m/d/y",$last) ;

}

?>

Any help is hugely appreciated.


Kind regards,
paffley

sunfighter
01-07-2012, 03:56 PM
Your missing a close bracket. The if ( $change > 86400) keeps the echo from executing. LastVisit needs to be in quotes.

A little lean up and we have

<?php
if(isset($_COOKIE['LastVisit']))
{
$last = $_COOKIE['LastVisit'];
}
$year = 31536000 + time() ;
setcookie('LastVisit', time (), $year) ;

if(isset($last))
{
echo "Last visit was" . date("m/d/y", $last);
}

?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum