ShadowIce Posted February 4, 2010 Share Posted February 4, 2010 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/190920-please-help-php-redirect-wont-work-at-all/ Share on other sites More sharing options...
oni-kun Posted February 4, 2010 Share Posted February 4, 2010 And what exactly is your problem? Quote Link to comment https://forums.phpfreaks.com/topic/190920-please-help-php-redirect-wont-work-at-all/#findComment-1006792 Share on other sites More sharing options...
ShadowIce Posted February 4, 2010 Author Share Posted February 4, 2010 well, it's not refreshing at all. and when it did before, it didn't refresh to the right page Quote Link to comment https://forums.phpfreaks.com/topic/190920-please-help-php-redirect-wont-work-at-all/#findComment-1006793 Share on other sites More sharing options...
WolfRage Posted February 4, 2010 Share Posted February 4, 2010 Headers don't refresh a page, use a meta tag because not all users will have javascript enabled. Quote Link to comment https://forums.phpfreaks.com/topic/190920-please-help-php-redirect-wont-work-at-all/#findComment-1006795 Share on other sites More sharing options...
ShadowIce Posted February 4, 2010 Author Share Posted February 4, 2010 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/190920-please-help-php-redirect-wont-work-at-all/#findComment-1006798 Share on other sites More sharing options...
WolfRage Posted February 4, 2010 Share Posted February 4, 2010 Let's see the source. Quote Link to comment https://forums.phpfreaks.com/topic/190920-please-help-php-redirect-wont-work-at-all/#findComment-1006808 Share on other sites More sharing options...
ShadowIce Posted February 4, 2010 Author Share Posted February 4, 2010 <?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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/190920-please-help-php-redirect-wont-work-at-all/#findComment-1006809 Share on other sites More sharing options...
WolfRage Posted February 4, 2010 Share Posted February 4, 2010 Sorry what I meant was I wanted to see the source output from the browser, to make sure that you are echoing everything correctly. I should have been more specific. Quote Link to comment https://forums.phpfreaks.com/topic/190920-please-help-php-redirect-wont-work-at-all/#findComment-1006815 Share on other sites More sharing options...
ShadowIce Posted February 4, 2010 Author Share Posted February 4, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/190920-please-help-php-redirect-wont-work-at-all/#findComment-1006816 Share on other sites More sharing options...
WolfRage Posted February 4, 2010 Share Posted February 4, 2010 Ok so the meta is working now? So what is the expected results that you want to happen next? Quote Link to comment https://forums.phpfreaks.com/topic/190920-please-help-php-redirect-wont-work-at-all/#findComment-1006827 Share on other sites More sharing options...
oni-kun Posted February 4, 2010 Share Posted February 4, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/190920-please-help-php-redirect-wont-work-at-all/#findComment-1006829 Share on other sites More sharing options...
ShadowIce Posted February 4, 2010 Author Share Posted February 4, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/190920-please-help-php-redirect-wont-work-at-all/#findComment-1006830 Share on other sites More sharing options...
ShadowIce Posted February 4, 2010 Author Share Posted February 4, 2010 can someone else plz help? Quote Link to comment https://forums.phpfreaks.com/topic/190920-please-help-php-redirect-wont-work-at-all/#findComment-1006885 Share on other sites More sharing options...
ShadowIce Posted February 4, 2010 Author Share Posted February 4, 2010 does anyone else know how to fix this? Quote Link to comment https://forums.phpfreaks.com/topic/190920-please-help-php-redirect-wont-work-at-all/#findComment-1007086 Share on other sites More sharing options...
merylvingien Posted February 4, 2010 Share Posted February 4, 2010 Headers don't refresh a page, use a meta tag because not all users will have javascript enabled. Are you sure? How about header("Refresh: 5; URL=\"somescript.php\""); Quote Link to comment https://forums.phpfreaks.com/topic/190920-please-help-php-redirect-wont-work-at-all/#findComment-1007106 Share on other sites More sharing options...
ShadowIce Posted February 5, 2010 Author Share Posted February 5, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/190920-please-help-php-redirect-wont-work-at-all/#findComment-1007401 Share on other sites More sharing options...
oni-kun Posted February 5, 2010 Share Posted February 5, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/190920-please-help-php-redirect-wont-work-at-all/#findComment-1007425 Share on other sites More sharing options...
ShadowIce Posted February 5, 2010 Author Share Posted February 5, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/190920-please-help-php-redirect-wont-work-at-all/#findComment-1007569 Share on other sites More sharing options...
ShadowIce Posted February 5, 2010 Author Share Posted February 5, 2010 anyone......? Quote Link to comment https://forums.phpfreaks.com/topic/190920-please-help-php-redirect-wont-work-at-all/#findComment-1007659 Share on other sites More sharing options...
ShadowIce Posted February 6, 2010 Author Share Posted February 6, 2010 anyone?.. and i waited 12 hours to bump Quote Link to comment https://forums.phpfreaks.com/topic/190920-please-help-php-redirect-wont-work-at-all/#findComment-1007951 Share on other sites More sharing options...
ShadowIce Posted February 6, 2010 Author Share Posted February 6, 2010 if someone could show me how to do this, i would be greatful. this problem has bugged me for the last time Quote Link to comment https://forums.phpfreaks.com/topic/190920-please-help-php-redirect-wont-work-at-all/#findComment-1008077 Share on other sites More sharing options...
WolfRage Posted February 8, 2010 Share Posted February 8, 2010 POst what you have so far for each page that is involved. Use the php brakets to make it readable and scrollable, then I will look it over and try to give you a solution. Quote Link to comment https://forums.phpfreaks.com/topic/190920-please-help-php-redirect-wont-work-at-all/#findComment-1008814 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.