آی پی امداد
آی پی امداد
آریا الکترونیک parcham تکشو

کد آماده PHP: نمایش تاریخ آخرین بازدید و تعداد بازدیدهای صورت گرفته به کاربر توسط کوکی

nekooee

Senior Technical Supervisor
مدیرکل
معاونت انجمن
2007-09-21
6,774
29,824
ایران
کد زیر دفعه اول به کاربر عبارت "Welcom" نمایش داده میشه و از دفعات بعد تاریخ آخرین ورود به صفحه و تعداد بازدید را نمایش میدهد.
میتوندی بسته به نیاز خودتون کد رو ویرایش کنید.


<?php
// set the variable to 0, it'll matter only if the cookie for the variable is not set
$visitCounter = 0;
// if cookie is set for the variable, it'll go to $visitCounter and get added by 1; otherwise it'll show 0 for tha variable
if(isset($_COOKIE['visitCounter'])){
    $visitCounter = $_COOKIE['visitCounter'];
    $visitCounter ++;
}
// if the last visist cookie is set, it'll pass the value to $lastVisit, and it'll be displayed below;
if(isset($_COOKIE['lastVisit'])){
    $lastVisit = $_COOKIE['lastVisit'];
    
}
// set cookie for visitCounter
setcookie('visitCounter', $visitCounter++,  time()+3600); 
// set cookie for last visit
setcookie('lastVisit', date("d-m-Y H:i:s"),  time()+3600); 
// show the respected values

// is the variable is not set, say 'welcome', otherwise show the info about visit number and last visit date
if($visitCounter == 0){
    echo "Welcome";
} else {

echo "This is your visit number ".$visitCounter;
echo '<br>';
echo "Last time, you were here ".$lastVisit;

}
?> 


 
بالا