I need a way to check if the user supports cookies. Is there any variable or function I can use to check this? My problem is that if they dont have cookies then every page will add a record a MySQL table, instead of just adding one per visit to the site, and some of my statistics for active guest users will be thrown off.
Way to check for cookies?
you can use javascript to check but then the client has to have js enabled.
otherwise you can use a script to set a cookie, then redirect to a new page to see if the cookie is set, and then from there determine if the cookie was stored or not.
the js code is here: http://techpatterns.com/downloads/javascript_check_cookies.php
here is the php way.
splash.php
<?php
setcookie("test", "test", time()+3600);
header("Location: check.php");
?>
check.php
<?php
if (isset($_COOKIE['test'])) {
setcookie("test", "", time()-3600);
header("Location: main.php");
} else {
header("Location: nocookies.php");
}
?>
Is there a way to get javascript variables into php or how would I transfer the data?
you can use javascript to redirect to a nocookie page if necessary and then use php from there to realize they cant use cookies. but js is clientside and php is serverside so there is no direct way to have js talk to php without making a call to a new page.
js redirect command is
window.location="http://www.site.com/nocookies.php"
Well is there any way to get around SP2? As default the user has to click the little yellow bar and then click allow blocked content for my script to work. The problem is that the script to redirect non-javascript users works as soon as that part of the page loads:
<meta name="redirect" http-equiv="refresh" content="0;nojs.php">
<script>
redirect.content="";
redirect.http-equiv="";