mdmartiny Posted March 3, 2017 Share Posted March 3, 2017 I am trying to write a small script to run a file based on the directory that it is in. I have tried several different ways of doing this and none of them are working? I do not know what I am doing wrong and I am going insane. $path_parts = pathinfo($_SERVER['REQUEST_URI']); $path_parts = explode('/', $path_parts['dirname']); $path_parts = array_filter($path_parts); $dir = $path_parts[2]; echo $dir; if (isset($_GET['page'])) { $page = $_GET['page']; } else if ($dir = 'mail') { $page = 'inbox'; } else { $page = 'dashboard'; } The above code is what I have come up with so far. Quote Link to comment https://forums.phpfreaks.com/topic/303341-get-a-variable-from-an-array/ Share on other sites More sharing options...
Barand Posted March 3, 2017 Share Posted March 3, 2017 We don't know what your input values are. We don't know what you are expecting from those values. We don't know what "not working" means. You might as well try "Alexa! What is the page value?" Quote Link to comment https://forums.phpfreaks.com/topic/303341-get-a-variable-from-an-array/#findComment-1543677 Share on other sites More sharing options...
Jacques1 Posted March 3, 2017 Share Posted March 3, 2017 This doesn't look right: } else if ($dir = 'mail') { ^^^^^ But, yeah, a tiny bit of information might help. Besides, those directory check gymnastics look very weird and fragile. Why can't you have a proper routing mechanism like with your other pages? Quote Link to comment https://forums.phpfreaks.com/topic/303341-get-a-variable-from-an-array/#findComment-1543680 Share on other sites More sharing options...
mdmartiny Posted March 3, 2017 Author Share Posted March 3, 2017 This is my file structure -htdocs - cms -admin - mail index.php Using $_SERVER['REQUEST_URI'] in the index page. My Url will look like this www.example.dev/admin/mail/index.php?page=inbox if the query string is not attached to the URL. It should automatically place the variable there based on the file being in the mail folder. I am trying to get a variable for the mail folder of the URI. ($dir = $path_parts[2]). If the directory equals mail. It opens the "inbox" portion of the page variable; if not it defaults to the "dashboard". When I run the script that I currently get a blank page. The page does not get the "inbox" variable. Quote Link to comment https://forums.phpfreaks.com/topic/303341-get-a-variable-from-an-array/#findComment-1543681 Share on other sites More sharing options...
mdmartiny Posted March 3, 2017 Author Share Posted March 3, 2017 If I echo out the $dir variable it has 'mail' in it. Quote Link to comment https://forums.phpfreaks.com/topic/303341-get-a-variable-from-an-array/#findComment-1543683 Share on other sites More sharing options...
Jacques1 Posted March 3, 2017 Share Posted March 3, 2017 Look, none of us is a mind reader, and we're not sitting in front of your screen. If you want help with your code, we need to actually see that code (not just random fragments), and it's your job to do basic debugging. Like: What is the value of $page after the code above? Did you read my reply regarding the code error? And your directory check still makes no sense. Have you symlinked/copied the exact same script into multiple directories? Why would you do that? Quote Link to comment https://forums.phpfreaks.com/topic/303341-get-a-variable-from-an-array/#findComment-1543684 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.