ryan1234 Posted December 13, 2012 Share Posted December 13, 2012 I'm trying to get the URL of the current page and if it equals the stated URL, then the page redirects. $page = $_SERVER['PHP_SELF']; if ($page == "index.php") { header('Location: index.php?id=1'); } However the code above doesn't seem to be working. Any ideas? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/271959-url/ Share on other sites More sharing options...
Pikachu2000 Posted December 13, 2012 Share Posted December 13, 2012 Have you echoed $_SERVER['PHP_SELF'] to see if that gives you a clue what the problem might be? Quote Link to comment https://forums.phpfreaks.com/topic/271959-url/#findComment-1399164 Share on other sites More sharing options...
Christian F. Posted December 13, 2012 Share Posted December 13, 2012 Also, I recommend reading this post. To secure yourself against XSS attacks. Quote Link to comment https://forums.phpfreaks.com/topic/271959-url/#findComment-1399172 Share on other sites More sharing options...
ryan1234 Posted December 13, 2012 Author Share Posted December 13, 2012 Thanks. I've got it working, however it goes into a continuous loop. How would I stop this once I'm on the redirected page? Quote Link to comment https://forums.phpfreaks.com/topic/271959-url/#findComment-1399178 Share on other sites More sharing options...
mrMarcus Posted December 13, 2012 Share Posted December 13, 2012 Thanks. I've got it working, however it goes into a continuous loop. How would I stop this once I'm on the redirected page? Redirect to somewhere that isn't index.php. All your doing is checking to see if the page you're on is index.php, and if it is, redirect to index.php (which is causing your infinite loop). Quote Link to comment https://forums.phpfreaks.com/topic/271959-url/#findComment-1399181 Share on other sites More sharing options...
Christian F. Posted December 13, 2012 Share Posted December 13, 2012 You don't even need the redirect, just set $_GET['id'] directly. Quote Link to comment https://forums.phpfreaks.com/topic/271959-url/#findComment-1399185 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.