[PHP] Must Have Cookies. PHP/JavaScript
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 ___ SUMMER ART PRINT SALE at www.PopStreet.com Save an additional 10% off art print orders of $50 or more. Type in coupon code jemc when checking out. ___ Find the right art print for your home. * Search by artist, color, art style and subject. * Preview the art prints against your wall color. * Specializing in contemporary, abstract and African American art. * Every day discounts on thousands of fine art prints. PopStreet.com is your avenue to art. http://www.popstreet.com ___ Coupon may be redeemed from June 27 through July 31, 2001. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Must Have Cookies. PHP/JavaScript
On the *2nd* page request you can check for your cookie in $HTTP_COOKIE_VARS. If it is not there, cookies are disabled in the browser. Here's a kludge to make your first page the 2nd page request: just start your session on index, then META redirect to the next page; this 2nd page is where you actually output HTML to the browser, and also check for the cookie. function check_cookies() { global $HTTP_COOKIE_VARS; if(!$HTTP_COOKIE_VARS[PHPSESSID]) { // redirect to the cookie error page; exit(); } Kirk -Original Message- From: Jeff Gannaway [mailto:[EMAIL PROTECTED]] Subject: [PHP] Must Have Cookies. PHP/JavaScript 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? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Must Have Cookies. PHP/JavaScript
Not to sound overly obvious, but try this. setcookie(cookieusername,$username,time()+6048000,/,,0); $cookieusername = $HTTP_COOKIE_VARS[cookieusername]; if (!$cookieusername){ echoSorry, no cookie, no page.; die(); } =- Jonathan Campbell ( [EMAIL PROTECTED] ) Mid days haze and I'm still not awake I got everything going but my bills are still late Funnier than hell and I think it's a blast Life's like a laugh when you got no money Lyrics from Average Day by Aztek Trip ( http://www.aztektrip.com ) - Original Message - From: Jeff Gannaway [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, July 05, 2001 4:36 PM Subject: [PHP] Must Have Cookies. PHP/JavaScript 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 ___ SUMMER ART PRINT SALE at www.PopStreet.com Save an additional 10% off art print orders of $50 or more. Type in coupon code jemc when checking out. ___ Find the right art print for your home. * Search by artist, color, art style and subject. * Preview the art prints against your wall color. * Specializing in contemporary, abstract and African American art. * Every day discounts on thousands of fine art prints. PopStreet.com is your avenue to art. http://www.popstreet.com ___ Coupon may be redeemed from June 27 through July 31, 2001. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Must Have Cookies. PHP/JavaScript
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Must Have Cookies. PHP/JavaScript
With a good start from the folks on this list and a little JavaScript digging, I found an excellent solution to my problem that I thought I'd share: Problem: Want to set a cookie then test for it on the same page. I don't want to to do page redirection to ensure optimal search engine friendliness. Solution: Set the cookie in PHP then test for the cookie with JavaScript. Code example below: ? if (! $MySession) { $SessionID = 2001 A Space Odyssey; setCookie('MySession',$SessionID,time()+6048000,/,,0); } ? h t m l !--html tag done that way to ensure non-HTML appearance in e-mail head titleTest Page/title SCRIPT LANGUAGE=JavaScript cookie_name = MySession; var Session; function getSession() { if(document.cookie) { index = document.cookie.indexOf(cookie_name); if (index != -1) { namestart = (document.cookie.indexOf(=, index) + 1); nameend = document.cookie.indexOf(;, index); if (nameend == -1) { nameend = document.cookie.length; } Session = document.cookie.substring(namestart, nameend); return Session; } } } Session=getSession(); if (!Session) { CookieMessage = Cookies are not enabled. You can browse the site, but will need to enable them to be able make a purchase. } else { CookieMessage = } /SCRIPT /head body SCRIPT LANGUAGE=javascript document.write(CookieMessage); /SCRIPT blah, blah, blah, the rest of the web page... Enjoy, Jeff Gannaway At 03:36 PM 7/5/01 -0500, 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. Thanks, Jeff Gannaway -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]