Jump to content

PLEASE HELP! PHP redirect wont work at all! ><


ShadowIce

Recommended Posts

I need this to refresh a page every 5 seconds

 

and if it detects javascript is on then take user to index

 

else

 

refresh and stay on same page.

 

<?php
ob_start();

$js = (isset($_GET['js']) && $_GET['js']=='1') ? 1 : 0;
if ($js)
{
?>
<?php
$urlRefresh = "index.php";
header("Refresh: 5; URL=\"" . $urlRefresh . "\""); // redirect in 5 seconds
?>
<?php
}else{
$urlRefresh = "enable_javascript.php";
header("Refresh: 5; URL=\"" . $urlRefresh . "\""); // redirect in 5 seconds
}
?>
blah
<?php
ob_end_flush();
?>

Link to comment
Share on other sites

it's still not refreshing -.-

 

<?php
ob_start();

$js = (isset($_GET['js']) && $_GET['js']=='1') ? 1 : 0;
if ($js)
{
?>
<?php
$urlRefresh = "index.php";
echo "<meta http-equiv=\"refresh\" content=\"5; URL=$urlRefresh\">\r\n";
//header("Refresh: 5; URL=\"" . $urlRefresh . "\""); // redirect in 5 seconds
?>
<?php
}else{
$urlRefresh = "enable_javascript.php";
echo "<meta http-equiv=\"refresh\" content=\"5; URL=$urlRefresh\">\r\n";
//header("Refresh: 5; URL=\"" . $urlRefresh . "\""); // redirect in 5 seconds
}
?>
blah
<?php
ob_end_flush();
?>

Link to comment
Share on other sites

<?php
ob_start();

$js = (isset($_GET['js']) && $_GET['js']=='1') ? 1 : 0;
if (!$js)
{
?>
<?php
$urlRefresh = "index.php";
echo "<meta http-equiv=\"refresh\" content=\"5; URL=$urlRefresh\">\r\n";
//header("Refresh: 5; URL=\"" . $urlRefresh . "\""); // redirect in 5 seconds
?>
<?php
}else{
$urlRefresh = "enable_javascript.php";
echo "<meta http-equiv=\"refresh\" content=\"5; URL=$urlRefresh\">\r\n";
//header("Refresh: 5; URL=\"" . $urlRefresh . "\""); // redirect in 5 seconds
}
?>


<?php
function GetFileDir($php_self){
$filename = explode("/", $php_self); // THIS WILL BREAK DOWN THE PATH INTO AN ARRAY
for( $i = 0; $i < (count($filename) - 1); ++$i ) {
$filename2 .= $filename[$i].'/';
}
return $filename2;
}
?>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access <?php echo GetFileDir($_SERVER['PHP_SELF']);?>
 on this server.</p>
<hr>
<center>
<table cellpadding="0" cellspacing="0" border="0" width="550">
<tr><td width="100%" valign="top" class="PPDesTxt"><b>Are you using a browser that doesn't support JavaScript?</b></td></tr>

<tr><td width="100%" valign="top" class="PPDesTxt">If your browser does not support JavaScript, you can upgrade to a newer browser, such as <a href="http://www.microsoft.com/windows/internet-explorer/default.aspx">Microsoft® Internet Explorer 8</a> or <a href="http://www.mozilla.com/en-US/firefox/upgrade.html">Mozilla Firefox 3.5</a>.</td></tr>

<tr><td width="100%" valign="top" class="PPDesTxt"><b>Have you disabled JavaScript?</b></td></tr>

<tr><td width="100%" valign="top" class="PPDesTxt">If you have disabled JavaScript, you must re-enable JavaScript to use this page. To enable JavaScript: </td></tr>
<tr><td width="100%" valign="top" class="PPDesTxt">For Mozilla Firefox: <br>
<ul><li>1: Click the 'Tools' button at the top of your browser</li></ul></td></tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" width="100%">

<tr><td width="100%" colspan="2"><img src="/images/T.gif" width="1" height="25" border="0"></td></tr>
</table></td>
</tr><tr><td>
</center>
<h2>Error 403</h3><hr>
<a href="<?php echo $thisFilename?>">Refresh</a><br>
<address>
  <span><?php echo date('l, F jS Y h:i:s A'); ?><br />
  Apache/2.2.12 (Win32) DAV/2 mod_ssl/2.2.12 OpenSSL/0.9.8k mod_autoindex_color PHP/5.3.0 mod_jk/1.2.28 mod_perl/2.0.4 Perl/v5.10.0</span>
</address>
</body></html>
<?php
ob_end_flush();
?>

Link to comment
Share on other sites

ok, it SORTA works now.

 

prob is if they have jscript off

 

then it 1st takes them to the index page

 

THEN back to the enable jscript page

 

which is not right

 

output

 

<meta http-equiv="refresh" content="5; URL=index.php">


<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /imagepos/ on this server.</p>
<hr>
<center>
<table cellpadding="0" cellspacing="0" border="0" width="550">
<tr><td width="100%" valign="top" class="PPDesTxt"><b>Are you using a browser that doesn't support JavaScript?</b></td></tr>

<tr><td width="100%" valign="top" class="PPDesTxt">If your browser does not support JavaScript, you can upgrade to a newer browser, such as <a href="http://www.microsoft.com/windows/internet-explorer/default.aspx">Microsoft® Internet Explorer 8</a> or <a href="http://www.mozilla.com/en-US/firefox/upgrade.html">Mozilla Firefox 3.5</a>.</td></tr>

<tr><td width="100%" valign="top" class="PPDesTxt"><b>Have you disabled JavaScript?</b></td></tr>

<tr><td width="100%" valign="top" class="PPDesTxt">If you have disabled JavaScript, you must re-enable JavaScript to use this page. To enable JavaScript: </td></tr>
<tr><td width="100%" valign="top" class="PPDesTxt">For Mozilla Firefox: <br>
<ul><li>1: Click the 'Tools' button at the top of your browser</li></ul></td></tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" width="100%">

<tr><td width="100%" colspan="2"><img src="/images/T.gif" width="1" height="25" border="0"></td></tr>
</table></td>
</tr><tr><td>
</center>
<h2>Error 403</h3><hr>
<a href="">Refresh</a><br>
<address>
  <span>Thursday, February 4th 2010 08:48:32 AM<br />
  Apache/2.2.12 (Win32) DAV/2 mod_ssl/2.2.12 OpenSSL/0.9.8k mod_autoindex_color PHP/5.3.0 mod_jk/1.2.28 mod_perl/2.0.4 Perl/v5.10.0</span>
</address>
</body></html>

Link to comment
Share on other sites

Why not use JS as the redirector? Start off on the enable_JS page, and if JS is enabled it will redirect them (onLoad ..etc). If JS is not enabled, JS won't redirect them and they'll stay on the page. It's pointless to juggle headers around for this ename purpose.

Link to comment
Share on other sites

the expected results are that if js=0

then it will redirect them to the same page WITHOUT going back to my main page and THEN taking them back to enable_javascript.php

 

else

 

if js=1

 

then redirect them to index.php WITHOUT going to enable_javascript.php and THEN going to index.php

Link to comment
Share on other sites

that's not the problem.

 

the prob is its doing above:

 

the expected results are that if js=0
then it will redirect them to the same page WITHOUT going back to my main page and THEN taking them back to enable_javascript.php

else

if js=1

then redirect them to index.php WITHOUT going to enable_javascript.php and THEN going to index.php

Link to comment
Share on other sites

if (isset($_GET['js']) && $_GET['js'] == 0) {
    header('Refresh: 5; url=enable_javascript.php');
} else {
    header('Refresh: 5; url=index.php');
}

 

Turn output buffering off please, And tell me:

  a) What script are you calling this from, the index.php itself?

  b) Where is the GET value 'JS' defined, and why does it need to be refreshed every 5 seconds?

 

I don't see a point in this, you're just trying useless code for no apprent reason , you may as well not even call this a PHP question.

Link to comment
Share on other sites

the point of the 5 second refresh is because i cant tell the browser if their javascript is enabled or not. only on REFRESH i can do that and its not the index file it uses:

 

<noscript>

metarefresh here

</noscript>

 

and if they have noscript on, then it redirects them to enable_javascript.php where im having the problem above

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.