PDA

View Full Version : Session Cookie


Moonlight
06-01-1999, 05:36 PM
How could we do Session Cookies in PHP?

It would check if there is a session cookie, if not, it would ask for user id and password. Then, for all the other PHP pages, it would use the user id and password that the user entered on one page.

It would also be useful to pass form data without having to pass it through each page.

I created a small system in ASP that does the above and would like to be able to convert it into PHP.

Thanks,

Frederic Hutow

Terra
06-01-1999, 05:58 PM
www.aota.net/ubb/Forum15/HTML/000050.html (http://www.aota.net/ubb/Forum15/HTML/000050.html)

--
Terra
--Cookie Monster--
FutureQuest

Justin
06-01-1999, 06:39 PM
Actually, rather than using that library, there is a much easier way...

SetCookie("cookie_name", "cookie_data", time());

This will set the cookie named <font color=#FF0000>cookie_name</font> to hold the value <font color=#FF0000>cookie_data</font>, and set to expire now (or you can set it to expire in the past - either way). It will of course still be valid for the remainder of the session.

You could, for easier use by your users, make it a 1 hour or so:

SetCookie(&quot;cookie_name&quot;, &quot;cookie_data&quot;, time()+3600);

Or one day:

SetCookie(&quot;cookie_name&quot;, &quot;cookie_data&quot;, time()+86400);

Then provide a logout button that would allow them to delete the cookie:

SetCookie(&quot;cookie_name&quot;);

With no other arguments.

For more info on PHP's SetCookie() function, see http://www.php.net/manual/html/function.setcookie.html

Hope this helps :)

<edit>
I'm not sure if you know this or not, but the resulting cookie will be available as a variable with the same name as the cookie, so in the next page called (cookies can't be retrieved until after they're set :)), you would have the equivelant of:

$cookie_name = &quot;cookie_data&quot;;
</edit>

------------------
Justin Nelson
FutureQuest Support
[This message has been edited by Justin (edited 06-01-99)]

Rich
06-01-1999, 08:19 PM
Speaking of cookies....

I noticed this past weekend while viewing the logs-cgi/script that whenever cgi executes a cookie named htscallerid is listed in the environment. Who tossed this cookie, anyhow?

Rich
-- got milk?



[This message has been edited by Rich (edited 06-01-99)]

Terra
06-01-1999, 10:39 PM
Hmmm, that's a new one on me...[nbsp][nbsp]Perhaps one of your scripts is leaking this somehow as I don't have cookies (mod_usertrack) turned on in the Apache core...

--
Terra
-- got money?!?--
FutureQuest