Zubrag.com
July 23, 2019, 04:39:09 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Cookie detection  (Read 8977 times)
mcmlxi
Newbie
*
Posts: 11


« on: December 14, 2007, 06:45:20 PM »

Does anybody know how I can check a visitor's browser for cookie support using php? I have tried several Java scripts but they are just unreliable at best. If the user has Java turned off, it just doesn't work - obviously. Is there anything out there in php that can check whether the visitor's browser accepts cookies, and if it doesn't accept them maybe even let them know to enable cookies and redirect them to a different page?

Logged
zubrag
Administrator
Hero Member
*****
Posts: 788


WWW
« Reply #1 on: December 18, 2007, 02:14:56 AM »

Maybe following would help. It will try to set cookie, than refresh automatically using meta refresh tag, and will check if cookie set. Did not try it, so may not work.


checkcookie.php
Code:
<?php

// check if cookie is set
if(isset($_GET['check'])) {
  if (isset(
$_COOKIE['cookie-name-here'])) {
    
// redirect to cookies enabled page
    
header('Location: http://example.com/cookies.php');
  }
  else {
    
// redirect to cookies not enabled page
    
header('Location: http://example.com/no_cookies.php');
  }
}

// set some cookie
setcookie("cookie-name-here""some-value");
?>

<html>
<head>
<meta http-equiv="refresh" content="0;url=http://example.com/checkcookie.php?check=1" />
</head>
<body></body>
</html>
Logged
mcmlxi
Newbie
*
Posts: 11


« Reply #2 on: December 18, 2007, 12:48:17 PM »

Actually it does work just fine. Thanks zubrag!

The only problem I run into is when testing it, on one of my computers with IE 7 it goes to the "accept cookies" page even when disabling all cookies. That's what I don't understand. I had a similar script to yours, but that one particular machine keeps refusing to play by the rules. It keeps going to the "accept" page when everything (cookie-wise) is disabled on it. So of course I thought I had it all wrong but I have the same problem with your script, too.

Other than that, it works with IE 7 on my other computer, Opera, Firefox, and IE 6. Safari is a totally different issue, though.

But again, thank you.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC