Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Prakhar Patwa
Prakhar Patwa
11,260 Points

question regarding setcookie

working on login/logout system i have added a remember me functionality

cookieset('email',$email,time()+60); //it means it going to be set for 60 sec. and then it will be logout.

please test it, prakharpatwa.com/login when i check in the google chrome setting<advance setting<all cookies and site data it showing the expire time is in 2032 years, which is driving me crazy,

How to deal with it? please enter in the login page u_id - asthasharma@gail.com pass - 12345

At least it should be setcookie(), not cookieset().

1 Answer

Codin - Codesmite
Codin - Codesmite
8,600 Points

The Syntax is setcookie() not cookieset().

Example:

<?
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
?>

The "/" I have added after the duration is to set the path that the cookie applys too, "/" will set it to be availible across the entire domain, the default setting is the directory of the location the cookie was set. So if you set the cookie in a file located at "/includes/header.php" for example, the cookie will only be valid within the "/includes" directory.