Jump to content

Get a variable from an Array


mdmartiny

Recommended Posts

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. 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.