phreak3r Posted February 4, 2018 Share Posted February 4, 2018 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']); } } Link to comment Share on other sites More sharing options...
archive Posted February 4, 2018 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'); 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! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.