Current location: Hot Scripts Forums » Programming Languages » PHP » Sessions & Cookies


Sessions & Cookies

Reply
  #1 (permalink)  
Old 07-13-04, 01:35 AM
rocky's Avatar
rocky rocky is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Sessions & Cookies

Hi all,

I want to display the information of when the user visited the last. Can this be done via a cookie or a Session .

Please advice ..
Thanks a lot
Reply With Quote
  #2 (permalink)  
Old 07-13-04, 09:32 AM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
You can use a cookie for that, but the problem is that some users block all cookies in their browser. So the safest way to do this is by using a combination of both cookies and IP's.

Of course for those users that have a dynamic IP, you will not be able to keep track of them using their IP, since their IP changes everytime they connect to their ISP.

Here is how to set the cookie:

$cookie = setcookie('cookie_name','Your text goes in here! ',time() + (3600));

And this is how you detect to see if the user has already visited your site or not (to see if the cookie is set or not):

if (isset($_COOKIE['cookie_name']))
{
$cookieval = $_COOKIE['entry'];
echo $cookieval;
}
__________________
Reply With Quote
  #3 (permalink)  
Old 07-14-04, 10:42 AM
optix's Avatar
optix optix is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Just have your script log the date time stamp of thier login every time they log in and place it in your MySQL database in a field in the same table as their other user info. Then display it the next time they log in.

You said user so I assume you mean that they all log in. If you mean visitors that's a whole different story. There really is no way to guarantee it will work with all visitors because your site will have no absolute way to identify visitors like it can do with users.
__________________
[B] ModernConspiracy.com - Conspiracy Theory Forums (Talk Conspiracy)
DIYAutoForum.com - DIY Auto Forum
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
The power of sessions? perleo PHP 3 07-25-05 06:32 AM
Multiple sessions Kaanha PHP 2 01-16-04 10:39 AM
Can't seem to get the cookies to the cookie_jar benny666 Perl 1 10-28-03 04:54 AM
PHP & sessions, why won't it work? TinnyFusion PHP 1 10-04-03 01:51 PM
how to get my sessions script work with cookies JM007 PHP 1 06-24-03 08:06 AM


All times are GMT -5. The time now is 05:11 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.