Jump to content

Archived

This topic is now archived and is closed to further replies.

Drezard

PHP Cookies

Recommended Posts

Hello, Im using this code to create a cookie:

[CODE]
<?php
$user = $_SESSION['userinfo'];
setcookie('user', $user, time()+36000*24*365);
session_destroy();
?>
[/CODE]

In a past script that redirects to this one, it sets 'userinfo' as $user. So is this correct (its at the very top of the script).

- Cheers, Daniel

Share this post


Link to post
Share on other sites
It should be fine, so long as $user on the previous page had something assigned to it.

You might want to include a few more parameters in your call to setcookie() though.  Like 'path' and 'domain'

Regards
Huggie

Share this post


Link to post
Share on other sites
would be better to use [code]<?php

unset($_SESSION['userinfo']);

?>[/code]

instead of session_destroy() for that scenario, there may be other session data that you want to use later ..[/code]

Share this post


Link to post
Share on other sites

×

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.