phreak3r Posted February 4, 2018 Share Posted February 4, 2018 (edited) I am trying to redirect a user from out of a page in another directory. I may have to break the task up into two functions and just call the appropriate function. Although, I do not want to do that if I do not have to. The dir is setup like this.... soapbox |-----channel | |------channel.php | | | | With the current algorithm in the function, if the user is at soapbox/channel/channel.php/, they would (or should) be re-routed to soapbox/ where the index.php file is automatically displayed. However, the user is re-routed to soapbox/channel/index.php, which does not exist. I have var_dumped the $_SERVER['HTTP_REFERER'] variable which returns/prints NULL. Is there any other way to achieve my task before splitting up the tasks into two functions and calling the appropriate function, in the case where user's are trying to access a page in a sub-dir of soapbox and need to be routed back to soapbox/? (What a run-on!) EDIT (display function): function isLoggedIn() { if (!(isset($_SESSION['logged_in_user'])) && $_SERVER['HTTP_REFERER'] == 'http://localhost/soapbox/channel/channel.php') { header('Location: ../index.php'); } else if (!(isset($_SESSION['logged_in_user']))) { //header('Location: index.php'); var_dump($_SERVER['HTTP_REFERER']); } } Edited February 4, 2018 by phreak3r Quote Link to comment Share on other sites More sharing options...
Solution archive Posted February 4, 2018 Solution Share Posted February 4, 2018 Use a root based path as you might not know where you are redirecting from: header('Location: /soapbox/index.php');// same as typing http://localhost/soapbox/index.php #header('Location: /new_page.php'); #header('Location: /index.php'); #header('Location: /soapbox/index.php'); #header('Location: /soapbox/channel/index.php'); 1 Quote Link to comment Share on other sites More sharing options...
phreak3r Posted February 5, 2018 Author Share Posted February 5, 2018 Use a root based path as you might not know where you are redirecting from: header('Location: /soapbox/index.php');// same as typing http://localhost/soapbox/index.php #header('Location: /new_page.php'); #header('Location: /index.php'); #header('Location: /soapbox/index.php'); #header('Location: /soapbox/channel/index.php'); Thank you, archive! That seemed to do the trick! I had tried what you suggested above before, but with /index.php and soapbox/index.php (without the root-based path) and it wouldn't work. Thank you again archive! Quote Link to comment 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.