note 42541 added to function.session-start
| From: | charlie at linuxdsl dot co dot uk | Date: | Thu, 20 May 2004 16:59:31 +0000 |
| Subject: | note 42541 added to function.session-start | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-69881@lists.php.net to get a copy of this message | ||
The following code is a nice simple way to check for cookie support without needing any intermediary
pages to check it has been set.
// Set the name of the cookie (nicer than default name)
session_name("SID");
// Set cookie to expire way into the future so it persists
session_set_cookie_params (60*60*24*365*10, '/', '.mydomain.com',0);
session_start();
if ( SID != "" ) {
header("Location: /nocookie.php");
exit();
}
If you would also like to check for a certain value (e.g. to see if they are logged in) you could
use this code instead:
session_name("SID");
session_set_cookie_params (60*60*24*365*10, '/', '.mydomain.com',0);
session_start();
if ( SID != "" ) {
header("Location: /nocookie.php");
exit();
} else {
if (!(isset($_SESSION['uid']))) {
header("Location: /expired.php");
exit();
}
}
----
Manual Page -- http://www.php.net/manual/en/function.session-start.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42541
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42541&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42541&report=yes
Search -- http://master.php.net/manage/user-notes.php