/    Sign up×
Community /Pin to ProfileBookmark

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

to post a comment
PHP

13 Comments(s)

Copy linkTweet thisAlerts:
@JonathanJul 14.2003 — what is this?

$_GET["js"];
Copy linkTweet thisAlerts:
@Tasmanian_DevilauthorJul 14.2003 — Some to do with checking for Javascript.
Copy linkTweet thisAlerts:
@JonathanJul 14.2003 — is js a variable
Copy linkTweet thisAlerts:
@brendandonhueJul 14.2003 — 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)
[code=php]
<?
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!";
}
}
?>
[/code]

Basically it sets a cookie then checks for its existence.
Copy linkTweet thisAlerts:
@JonathanJul 14.2003 — noted
Copy linkTweet thisAlerts:
@Tasmanian_DevilauthorJul 14.2003 — brendandonhue~

can I set it up so when javascript is enabled then it checks the cookies?

Thanks
Copy linkTweet thisAlerts:
@brendandonhueJul 14.2003 — 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?
Copy linkTweet thisAlerts:
@Tasmanian_DevilauthorJul 14.2003 — 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).
Copy linkTweet thisAlerts:
@brendandonhueJul 14.2003 — <?

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');

}

}

?>
Copy linkTweet thisAlerts:
@Tasmanian_DevilauthorJul 14.2003 — How do I combined the two php together to work?
Copy linkTweet thisAlerts:
@brendandonhueJul 14.2003 — ??

I just posted the script.
Copy linkTweet thisAlerts:
@Tasmanian_DevilauthorJul 14.2003 — sorry I am tring to learn php, sorry bout htat
Copy linkTweet thisAlerts:
@brendandonhueJul 14.2003 — ok-good luck with it lol. I'm learning too.
×

Success!

Help @Tasmanian_Devil spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...