1

I use this PHP code for find the url path of a script page :

define("URL", dirname($_SERVER['REQUEST_URI']));

On my PC 1, I get this result with this url : htt://site1/abc/ :

/abc

but on my PC 2, I get this result with the same URL :

\

Don't understand why. If i add 'index.php', that's ok on PC 2

My goal is create a wizard installation and put the url path in the config file.

2
  • 2
    I'm going to take a wild guess, ones a unix box and ones a windows box? Commented Jun 24, 2014 at 19:38
  • No, PC 1and 2 are on Win 7 with EasyPhp 14.1VC9 Commented Jun 24, 2014 at 19:39

1 Answer 1

1

You may get unexpected results with dirname(), see the example in the manual:

echo "2) " . dirname("/etc/") . PHP_EOL; // 2) / (or \ on Windows)

Use parse_url() instead:

$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$path = '/'.implode('/', explode('/', ltrim($path, '/'), -1));
define("URL", $path);
Sign up to request clarification or add additional context in comments.

2 Comments

I get '/' on PC 1 instead of /abc
@Portekoi Updated the code, can you please try again?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.