Skip to content

Instantly share code, notes, and snippets.

@art2code
Created May 3, 2012 08:48
Show Gist options
  • Select an option

  • Save art2code/2584441 to your computer and use it in GitHub Desktop.

Select an option

Save art2code/2584441 to your computer and use it in GitHub Desktop.
php: check if js and cookie enabled
<?php
ob_start();/* header buffer */
session_start();
### Make cookies if they don't exist #######################
if(!$_SESSION['exists']){
$_SESSION['exists']= 'off';
setcookie("exits", "data");
}
### Test for $_SESSION cookies being enabled ##############
if($_SESSION['exists']== 'off'){
if($_GET['js']){
if (!$_COOKIE["exits"]){
$err= $err. "Cookie: Error<br>";
}
}
### Process $_GET ##########################################
if($_GET['js']== "on"){/*get sent with js*/
$jsOn= "on";
}elseif($_GET['js']== "off"){/*get sent with meta header*/
$err= $err. "Javascript: Error<br>";
}else{
?>
<script language="JavaScript">
location.href = location.href+'?js='+'on';/*send get with js*/
</script>
<noscript>
<!/* send get with header*/>
<meta http-equiv="refresh" content="0;url=<?php print $PHP_SELF. '?js=off' ?>"/>
</noscript>
<?php
}
}else{
$err= $err. "Session Cookie: Error<br>";/*session cookie error*/
}
if($_SESSION['exists'] && $_COOKIE["exits"] && $jsOn== "on"){
$_SESSION['exists']= "on";
}
### Add program code ########################################
if($_SESSION['exists']== 'on'){
print"<h3>Add Program Script or Includes<br><br>";
print"Session Cookies: Enabled<br>";
print"Javascript: Enabled<br>";
print"Cookies: Enabled<br></h3><br>";
}else{
### Add error code ###########################################
print"<h3>Add Error Script or Includes<br><br>";
print "For the Website to function properly.<br>";
print "Javascript and Cookies should be enabled.<br><br>";
print "$err</h3><br>";
}
while (@ob_end_flush());
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment