+4 votes
in Programming Languages by (9.6k 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

+1 vote
by (11.1k points)

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.

From

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

to

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

...