Click to See Complete Forum and Search --> : Can someone PLEASE HELP me out?
Tasmanian Devil
07-16-2003, 08:02 AM
the following code, is to check to see if javascript is enabled, and if not, it goes to a page without frames. And if the javascript is enabled, it goes to a a page with frames. As well I would like the script to check for cookies enabled. So what I am really looking for is, a php to first search for cookies enabled and then javascript enabled, if only one or none of them are enabled, I want the user to be sent to one page, if both are enabled, then the the user is sent to a page that is set up for both and has frames.
The code that follows does not do the javascript part of the check:
<?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
So, what exactly do you need?
Tasmanian Devil
07-16-2003, 08:38 AM
Pyro~
I am looking for a php to do the following: 1) check for cookies enabled. 2) check for javscript enabled. and if only one or none of the are enabled, to send the user to a certain page. And if both of them are enabled, to send the user to a certain page with frames.
Thanks Pyro
Do you have either one of them working?
Tasmanian Devil
07-16-2003, 08:54 AM
The above script is to check for javascript but it does not work
Thanks
This returns 1 for each variable ($js and $cookies) if they are enabled:
<?PHP
setcookie("cookies","yes",time() +"3600");
$js = 0;
$cookies = 0;
if (isset($_GET["js"])) {
$js = 1;
}
if (isset($_COOKIE["cookies"])) {
$cookies = 1;
}
echo $js."|".$cookies;
?>
<html>
<head>
<script type="text/javascript">
if (!window.location.search.substr(1)) {
window.location.href = "test.php?js=yes"; //set test.php to the name of this page...
}
</script>
</head>
<body>
</body>
</html>
Tasmanian Devil
07-19-2003, 12:43 PM
pyro~
I was wondering, how to set the php up so that if one or both are 0 then goes to a differnet page?
Thanks
Try something along these lines:
<?PHP
setcookie("cookies","yes",time() +"3600");
$js = 0;
$cookies = 0;
if (isset($_GET["js"])) {
$js = 1;
}
if (isset($_COOKIE["cookies"])) {
$cookies = 1;
}
if ($cookies == 0 || $js == 0) { #in english: if $cookies equals zero OR $js equals 0
header("Location:http://www.yourdomain.com/nojsorcookies.php");
}
?>
Tasmanian Devil
07-20-2003, 09:08 AM
Pyro~
I am greatful of your help, but not sure if to combined the two php's you gave me into one or what you meant by your last reply. Can you explain a little better?
Thanks
I meant to replace the PHP part of my prior repley with that PHP. Like this:
<?PHP
setcookie("cookies","yes",time() +"3600");
$js = 0;
$cookies = 0;
if (isset($_GET["js"])) {
$js = 1;
}
if (isset($_COOKIE["cookies"])) {
$cookies = 1;
}
if ($cookies == 0 || $js == 0) { #in english: if $cookies equals zero OR $js equals 0
header("Location:http://www.yourdomain.com/nojsorcookies.php");
}
?>
<html>
<head>
<script type="text/javascript">
if (!window.location.search.substr(1)) {
window.location.href = "test.php?js=yes"; //set test.php to the name of this page...
}
</script>
</head>
<body>
</body>
</html>
Tasmanian Devil
07-20-2003, 11:04 AM
Pyro~
your php somewhat works, when just cookies are disabled, it still allows me to the page where they need to be enabled. And also do I need to do something when both are disabled, it just comes up a blank page, rahter than the page that should come up.
Thanks
That's what you asked for above:
how to set the php up so that if one or both are 0 then goes to a differnet page?Anyway, try this out:
<?PHP
setcookie("cookies","yes",time() +"3600");
$js = 0;
$cookies = 0;
if (isset($_GET["js"])) {
$js = 1;
}
if (isset($_COOKIE["cookies"])) {
$cookies = 1;
}
if ($cookies == 0 && $js == 0) { #in english: if $cookies equals zero AND $js equals 0
header("Location:http://www.yourdomain.com/nojsorcookies.php");
}
else { #if js and cookies are enabled
header("Location:http://www.yourdomain.com/enabled.php");
}
?>
Tasmanian Devil
07-20-2003, 01:50 PM
Pyro~
Not sure what I am doing wrong so here is the page (http://216.104.190.167/4.html) to check out and tell me what the heck I am doing wrong. If you do not mind.
Thanks
Well, let's start with the fact that it is a PHP page, and you gave it a .html extention. Try .php. Also, you forgot the JS part. Here is the whole thing:
<?PHP
setcookie("cookies","yes",time() +"3600");
$js = 0;
$cookies = 0;
if (isset($_GET["js"])) {
$js = 1;
}
if (isset($_COOKIE["cookies"])) {
$cookies = 1;
}
if ($cookies == 0 && $js == 0) { #in english: if $cookies equals zero AND $js equals 0
header("Location:http://www.yourdomain.com/nojsorcookies.php");
}
else { #if js and cookies are enabled
header("Location:http://www.yourdomain.com/enabled.php");
}
?>
<html>
<head>
<script type="text/javascript">
if (!window.location.search.substr(1)) {
window.location.href = "test.php?js=yes"; //set test.php to the name of this page...
}
</script>
</head>
<body>
</body>
</html>
Tasmanian Devil
07-22-2003, 01:08 PM
Pyro~
What am I doing wrong again?
Here is the page. (http://216.104.190.167/4.php)
Thanks
I get this error:
Parse error: parse error in /usr3/home/foxvalleynews.com/htdocs/4.php on line 12
What does line 12 look like?
Tasmanian Devil
07-22-2003, 01:20 PM
Pyro~
I am not sure I think it is one of the following lines:
if ($cookies == 0 && $js == 0) { #in english: if $cookies equals zero AND $js equals 0
header("Location:<a href="http://www.yourdomain.com/nojsorcookies.php" target="_blank">http://www.yourdomain.com/nojsorcookies.php</a>");
}
else { #if js and cookies are enabled
header("Location:<a href="http://www.yourdomain.com/enabled.php" target="_blank">http://www.yourdomain.com/enabled.php</a>");
I have not changed the domains yet as you can see, was just wondering if it work.
Thanks
Try the code in this (http://forums.webdeveloper.com/showthread.php?s=&postid=71704#post71704) post again. I think the forums did a bit of formating that might have messed it up...
Tasmanian Devil
07-22-2003, 01:32 PM
Pyro~
That one works great except, when the cookies only are enabled and the js is disabled, the user still goes to the enabled page rather than the disabled page.
Thanks
Not for me... You sure you actually had it disabled?
Tasmanian Devil
07-22-2003, 01:44 PM
Pyro~
Well I might no have. Well one last thing, how do I put that into my index.html? I want to have the user w/cookies and/or js disable to go to a page, and w/them enable to go to a page that has frame. here is what I had before, but the php does not work.
<?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
?>
can you help?
Thanks
The code I posted above does just that... just change the values of the redirects, and insert that code on your index.php page... For PHP to work, it must have a .php extention.
Tasmanian Devil
07-24-2003, 11:13 AM
Pyro~
I was wondering with your php you gave me, why can I only bypass the disabled page if I have every thing enabled as well as type in the www.----.com? out of four ways how I should be able to type it only one lets me by.
Thanks
You lost me on this part:
Originally posted by Tasmanian Devil
as well as type in the www.----.com? out of four ways how I should be able to type it only one lets me by.
Tasmanian Devil
07-24-2003, 11:22 AM
Pyro~
Sorry about that. now it is a total ramdom thing when it blocks me out or not. before I could not get through but now after ten minutes, I can get through. any reason?
Thanks
I've had problems setting the time() on cookies the way you did it ( time()+60*60*24*30 )
Try: time()+2592000
Tasmanian Devil
07-24-2003, 08:18 PM
Pyro~
Still having problems with the time issue.
Thanks
Hmmm... don't really know what to tell you. Try looking around http://us2.php.net/manual/en/function.setcookie.php and playing with some of the cookie examples and see if they work for you.