Jump to content

[SOLVED] Got Milk, Need Cookie


AV1611

Recommended Posts

I have done some minor stuff with cookies in the past, but need some guidance.

 

All I want to do is make a simple login that when completed it sends a cookie to the client that never expires, then everytime they come back to the site it checks to see if the cookie is present and if not then they login again.

 

1. Is that PHP only?

2. It's a low security site... I'm making a shoutbox from scratch is all.

3. I just need to know how to make the cookie not expire and how to check for it on return to the site.

 

 

Link to comment
Share on other sites

The cookie system does not allow to create a cookie for ever but you can just create a cookie to live of a long time enough to make sure the user wiill be dead by that time :P

 

 

setcookie("registered",$cookie_data,time()+60*60*24*365*10);

 

if im correct on how i set that it would be a ten year cookie which in computer world is forever who keeps the same machine that long?

 

 

Link to comment
Share on other sites

so, what is the syntax to see if they have the cookie set?

 

if(isset($_COOKIE['cookiename'])){

do some cool stuff for the person

}

else{

tell them to log in

}

 

like that?

 

I don't care about the info in the cookie but I guess I could put a sha1 hash of a keyword or whatever but I don't care I don't think... It's just a shoutbox...

 

Link to comment
Share on other sites

You should add some form of content to the cookie to authenticate the user as anyone can just create a cookie with the name you specified.

 

As for the subject of a user living 10 years I've been developing an InjureUser class for use as a tech support tool... if you'd like to use it when the cookie reaches 9 years + 11 months + 364 days, send me a message and I'll send you a copy when I'm finished with it.

Link to comment
Share on other sites

<?php

if(isset($_GET['set'])){

setcookie('shoutbox','shoutboxdata',time()+60*60*24*365*10);

header('Location: cookietest.php');

}

else{

if(isset($_COOKIE['shoutbox'])){

echo "cookie is set";

}

else{

echo "cookie is not set";

}

}

?>

 

Looks like that'll do it.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.