I'm using this variable to get the current page URL, like this:

  $request = $_SERVER["REQUEST_URI"];

  $page = (is_ssl() ? 'https' : 'http').'://';
  if ($_SERVER["SERVER_PORT"] != "80")
    $page .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$request;
  else $page .= $_SERVER["SERVER_NAME"].$request;

The app. I doing this for is public, and the problem is that on some sites (very rare) this variable returns the entire URL, including the domain name, not just the requested page. Is this a server misconfiguration?


Can u tell us what web server engines are running in those "very rare" faulty instances where your app is deployed? Apache, lighttpd, nginx?

Written by stillstanding

Probably Apache. Anyway I think I found the issue. This app. is for WordPress and the user has a WP plugin called WPML, which is either messing around with redirects or it's changing this variable.

Written by Alex

Accepted Answer

It could be somewhere in your code (or 3rd party package) is changing this variable.

You could grep.

grep -r -E '\$_SERVER\[[\'"]?REQUEST_URI[\'"]?\]\s?=[^=]+?'

That regex should find where $_SERVER['REQUEST_URI] is being assigned, and not just used normally or testing for equality, for example. Note too I removed the -i flag because PHP variables are case sensitive and so are array keys.

Written by alex
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki