...

View Full Version : PLEASE HELP! Can't get code to use header only one time if js=off!



ShadowIce
02-07-2010, 04:20 PM
I can't get this code to stop redirecting more than one time if javascript is off


<?php
ob_start();
?>
<noscript>
<?php
header('Location: enable-javascript.php');
?>
</noscript>
<html>
<head><title>Test</title></head>
<body>
blah
</body>
</html>

and dont tell me to use metas because they redirect WAY too slow even if i set it to 0. the whole point is to keep the user from seeing index.php at all if js is off

djm0219
02-07-2010, 04:26 PM
Add exit; after the header call.



<?php
header('Location: enable-javascript.php');
exit;
?>

ShadowIce
02-07-2010, 04:35 PM
didnt work

i REALLY need this script

because metas are WAY too slow

even if u set them to 0

abduraooft
02-07-2010, 04:36 PM
..and make sure that there's no call to header() redirect in your enable-javascript.php page.

PS: It's very pity to see the use of such a code by a regular user of CF

ShadowIce
02-07-2010, 04:38 PM
this is whats in enable-javascript.php:


<head>
<meta http-equiv="refresh" content="5;URL=<?php echo $_SERVER['PHP_SELF'];?>" />
<title>403 Forbidden</title>
</head>
<body>
<script>
location.href='index.php';
</script>
<h1>Forbidden</h1>
<p>You don't have permission to access <?php echo GetFileDir($_SERVER['PHP_SELF']);?>
&nbsp;on this server.</p>
<hr>
</body>
</html>

MattF
02-07-2010, 05:09 PM
No help found on IRC then?

ShadowIce
02-07-2010, 05:13 PM
Was I talking to u?

I think not

ShadowIce
02-07-2010, 05:40 PM
ANYWAY here's what i have:

index.php:


<?php
ob_start();
?>
<?php
if (isset($_POST['jstest'])) {
$nojs = FALSE;
} else {
// create a hidden form and submit it with javascript
echo '<form name="jsform" id="jsform" method="post" style="display:none">';
echo '<input name="jstest" type="text" value="true" />';
echo '<script language="javascript">';
echo 'document.jsform.submit();';
echo '</script>';
echo '</form>';
// the variable below would be set only if the form wasn't submitted, hence JS is disabled
$nojs = TRUE;
}
if($nojs){
header('Location: enable-javascript.php');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>test</title>
<body>
blah
</body>
</html>
<?php
ob_end_flush();
?>

MattF
02-07-2010, 05:51 PM
Was I talking to u?

I think not

Technically, yes, you were. You were addressing, (and asking for responses from), every registered member on this board. :thumbsup:

ShadowIce
02-07-2010, 06:33 PM
Yea, and now I'm ignoring u

kbluhm
02-07-2010, 07:14 PM
Slightly off topic (but just slightly): Why is it that people continue to help this guy? Every time he comes in here with a remedial issue I think he honestly believes his problems are the only ones worth solving... that we must drop everything and help him because he cannot figure out a lot of things that often take 5 seconds to Google... and when people offer constructive criticism he treats them like an idiot. I don't get it. :\

iLochie
02-07-2010, 07:34 PM
ShadowIce, I suggest you learn PHP before coding it. Headers cannot be inserted after any raw HTML, therefor it cannot appear in a <noscript> tag. Try again buddy. By the way, you're gonna tear yourself a new one with the amount of bandwidth you're going to waste. And disallowing your site to anyone who doesn't have JS enabled is just dumb. Some people actually turn off Javascript because it really shouldn't be needed. My suggestion is make your site degrade when JS is turned off, don't completely repel and users that have it turned off.

Edit: It's worth telling us any errors you encounter in the future, so we're not just shooting in the dark trying to solve you're retarded problems.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum