+4 votes
in Programming Languages by (40.5k points)

I am trying to check the URL of the home page using the following PHP code.

if ($_SERVER[REQUEST_URI] === '/'){

But this code is throwing the following warning message:

PHP Warning: Use of undefined constant REQUEST_URI - assumed 'REQUEST_URI' (this will throw an Error in a future version)

How can I fix this warning message? 

1 Answer

+2 votes
by (60.0k points)
selected by
Best answer

From the warning message, it's clear that you need to put REQUEST_URI inside the quote ('') to get rid of the warning message. If you don't put REQUEST_URI inside the quote, your code will throw an error in the future.

Make the following change in your code, and the warning message will be gone.


if ($_SERVER[REQUEST_URI] === '/'){


if ($_SERVER['REQUEST_URI'] === '/'){