n00b
n00b

Reputation: 336

$_SERVER['DOCUMENT_URI'] is empty

I migrated servers and now this variable $_SERVER['DOCUMENT_URI'] stopped working, what can I do?

I'm temporarily using this solution: $uri_parts = explode('?', $_SERVER['REQUEST_URI'], 2)[0]; but there's a lot of code that uses $_SERVER['DOCUMENT_URI'] and I don't want to be changing all of that.

Upvotes: 0

Views: 980

Answers (1)

Álvaro González
Álvaro González

Reputation: 146450

DOCUMENT_URI is not a standard variable as far as I can tell. Whatever, there're two things to note about the $_SERVER superglobal:

  • It isn't read-only.
  • It populates from several sources, including environment variables.

You can just set an environment variable by whatever mean you prefer (for instance, the SetEnv directive if you happen to use Apache) or simply put your own value right into the PHP variable.

Upvotes: 1

Related Questions