Re: Must Have Cookies. PHP/JavaScript

From: Date: Thu, 05 Jul 2001 22:12:42 +0000
Subject: Re: Must Have Cookies. PHP/JavaScript
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-56396@lists.php.net to get a copy of this message
Hi Jeff! On Thu, 05 Jul 2001, Jeff Gannaway wrote: > OK, I'm working on a site that absolutely must use a cookie containing a > session identifier. > > I know how to set a cookie through PHP, but I need to do something else too. > > The same page MUST identifier whether the cookie was accepted or not. I've > seen sites like NetFlix.com that will test to see if their cookie was > accepted, and if not, print up a page that says "Sorry, you've got have > your Cookies on or go somewhere else." > > Does anyone know how to do this with PHP, Java, or JavaScript? > > Code examples or example URLs would be appreciated. > > Thanks, > Jeff Gannaway [snip-long-sig] If you won't enable trans_sid, you'll only have cookie based session, so on each page you can test for cookie presence in $HTTP_COOKIE_VARS global array, or, if you have register_globals on (practice for newbies), in $GLOBALS. So, you'll supposedly have an "entrance" page: [index.php] <?php setCookie('haveCookies',1); Header('Location: http://site/main.php'); ?> [main.php] <?php if (empty($HTTP_COOKIE_VARS['haveCookies'])) { return include "error.php"; } // the rest of php code goes here. ?> And BTW of globals off, ppl complain it's a lot to type (yap, one of the virtues of a programmer, laziness), but hey you can assign those long-named arrays to something simple, so if you have to work a lot with, say, GET vars, just say $GV = $HTTP_GET_VARS; and go ahead w/ $GV. ciao -- teodor

« previous php.general (#56396) next »