-2

Possible Duplicate:
How do I get current page full URL in PHP

I want to do something like this:

if (current url is 'site.com/dir1')
    do something;
else if (current url is 'site.com')
    do something else;

What's a reliable way to find this out? Thanks.

Community
  • 1
  • 1
Ali
  • 261,656
  • 265
  • 575
  • 769

3 Answers3

2

You can synthesise it with:

'http' . (443 == $_SERVER['SERVER_PORT'] ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

For IIS you don't get REQUEST_URI:

if (!isset($_SERVER['REQUEST_URI'])) {
    $_SERVER['REQUEST_URI'] = substr($_SERVER['PHP_SELF'], 1);
    if (isset($_SERVER['QUERY_STRING'])) {
        $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
    }
}
Ja͢ck
  • 170,779
  • 38
  • 263
  • 309
1

Use $_SERVER['REQUEST_URI']. This should give you the URL that the visitor is using.

demize
  • 364
  • 1
  • 15
1
if($_SERVER['REQUEST_URI']=="url"){}

Should do the trick.