Page 1 of 1

How do I get the current URL into a variable?

Posted: Thu Aug 10, 2017 10:02 am
by simonmlewis
I need to get hold of the URL to identify if it is a /blog/ URL.

I have tried this on PHP7.1, but it is echoing nothing.

Code: Select all

<?php  
echo "The query string is: ".$_SERVER['QUERY_STRING'];  
?> 
What am I doing wrong?

Re: How do I get the current URL into a variable?

Posted: Thu Aug 10, 2017 11:46 am
by requinix
$_SERVER[QUERY_STRING] is half right.

Re: How do I get the current URL into a variable?

Posted: Fri Aug 11, 2017 3:10 am
by simonmlewis
$url = $_SERVER['REQUEST_URI'];

Re: How do I get the current URL into a variable?

Posted: Fri Aug 11, 2017 11:57 am
by thinsoldier
var_dump( $_SERVER );

And look at all the things you have to choose from. Google the key names to find out more about each.