Click to See Complete Forum and Search --> : Can this be done?


Tasmanian Devil
07-14-2003, 08:19 AM
Can I use php to see if cookies are enabled? and also use it with this code:
<?PHP
$js = $_GET["js"];
if($js==0){
setcookie("js", 0, time()+60*60*24*30, '/', '.foxvalleynews.com');
echo ('<html>
<title>Fox Valley Newspapers</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<frameset cols="134,*" frameborder="NO" border="0" framespacing="0" rows="*">
<frame name="leftFrame" scrolling="NO" noresize src="index-2.html">
<frame name="mainFrame" src="index-1.html">
</frameset>
<noframes>
<body bgcolor="#FFFFFF" text="#000000">
</body>
</noframes>
</html>');
} else if($js==1) {
setcookie("js", 1, time()+60*60*24*30, '/', '.foxvalleynews.com');
echo ('<html>
<title>Fox Valley Newspapers</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<frameset cols="134,*" frameborder="NO" border="0" framespacing="0" rows="*">
<frame name="leftFrame" scrolling="NO" noresize src="index-2.html">
<frame name="mainFrame" src="index-withJavaScript.html">
</frameset>
<noframes>
<body bgcolor="#FFFFFF" text="#000000">
</body>
</noframes>
</html>');
} else {
echo ("<h1>Please click <a href=\"jsEnabled.php\">here</a></h1>");
}
echo $_COOKIE["js"]; // print cookie value
?>

Thanks

Jonathan
07-14-2003, 11:53 AM
what is this?

$_GET["js"];

Tasmanian Devil
07-14-2003, 11:56 AM
Some to do with checking for Javascript.

Jonathan
07-14-2003, 11:57 AM
is js a variable

brendandonhue
07-14-2003, 12:13 PM
Yes JS is a variable and $_GET['js'] would mean its passed via the query string.

It looks like if js=0 they get a non javascript site, if js=1 they get it with javascript.


To test for cookies use this (i found it at another board)

<?
if(empty($enabled)) {
$page="$PHP_SELF?enabled=yes";
header( "Location: $page");
setcookie("testingforcookies", "yes");
} else {
if(empty($testingforcookies)) {
echo "Couldn't set cookie. You should prabably enable cookies...";
} else {
echo "Cookies are enabled!";
}
}
?>

Basically it sets a cookie then checks for its existence.

Jonathan
07-14-2003, 12:26 PM
noted

Tasmanian Devil
07-14-2003, 12:26 PM
brendandonhue~
can I set it up so when javascript is enabled then it checks the cookies?

Thanks

brendandonhue
07-14-2003, 12:31 PM
So you want to do one thing if they have JavaScript AND Cookies, and something different if they dont have both?
Or is it do something if they have both, something different if they have only one, something else if they have neither?

Tasmanian Devil
07-14-2003, 12:34 PM
brendandonhue~
If only cookies or javascript are enabled, or nither one are enabled to go to one page (no frames) but if both are enabled, then go to a differnet page (has frames).

brendandonhue
07-14-2003, 12:47 PM
<?
if(empty($enabled)) {
$page="$PHP_SELF?enabled=yes";
header( "Location: $page");
setcookie("testingforcookies", "yes");
} else {
if(empty($testingforcookies) || $_GET['js'] == "0") {
header('Location: noframes.html');
} else {
header('Location: frames.html');
}
}
?>

Tasmanian Devil
07-14-2003, 12:55 PM
How do I combined the two php together to work?

brendandonhue
07-14-2003, 12:59 PM
??
I just posted the script.

Tasmanian Devil
07-14-2003, 01:02 PM
sorry I am tring to learn php, sorry bout htat

brendandonhue
07-14-2003, 01:07 PM
ok-good luck with it lol. I'm learning too.