angerbeaver Posted December 20, 2007 Share Posted December 20, 2007 Hi, I have a page that uses JavaScript to re-direct the page, but if JavaScript is not enabled the page sits idly (while blank). if($_REQUEST['mode'] == "logout") { session_destroy(); unset($_REQUEST['mode']); echo ' <script type="text/javascript"> <!-- window.location = "https://www.website.ca/index2.php"; //--> </script>'; die(); } Now, if I made an html redirect after 4 seconds if($_REQUEST['mode'] == "logout") { session_destroy(); unset($_REQUEST['mode']); echo ' <script type="text/javascript"> <!-- window.location = "https://www.website.ca/index2.php"; //--> </script>'; <meta HTTP-EQUIV="REFRESH" content="0; url=http://www.website.ca/index2.php"> die(); } Is this like super bad coding? Is there a nicer/neater way of making sure they re-direct if JavaScript is not enabled? Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/82544-how-to-re-direct-with-javascript-disabled/ Share on other sites More sharing options...
p2grace Posted December 20, 2007 Share Posted December 20, 2007 If you can help it, avoid using javascript to redirect. Instead use php headers: header("Location: $redirect_url"); Quote Link to comment https://forums.phpfreaks.com/topic/82544-how-to-re-direct-with-javascript-disabled/#findComment-419617 Share on other sites More sharing options...
angerbeaver Posted December 20, 2007 Author Share Posted December 20, 2007 If I remember this has to be done before anything is written to the page right? Like any echo/print or any html tags? Quote Link to comment https://forums.phpfreaks.com/topic/82544-how-to-re-direct-with-javascript-disabled/#findComment-419626 Share on other sites More sharing options...
p2grace Posted December 20, 2007 Share Posted December 20, 2007 It has to be done before the html headers are set. So basically yes. But if you program it correctly you should be able to do it, and the user won't be able to bypass the redirect. Quote Link to comment https://forums.phpfreaks.com/topic/82544-how-to-re-direct-with-javascript-disabled/#findComment-419627 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.