I'm using basename($_SERVER['PHP_SELF'])
but this only gives me the page name e.g.
http://www.mysite.com/helloworld.php?name=Dan
I can only get "helloworld.php".
I need "helloworld.php?name=Dan"
There is also $_SERVER['QUERY_STRING']
, and $_SERVER['REQUEST_URI']
and many more.
In your case, you can get it like:
$whatiwant = $_SERVER['REQUEST_URI'];
or
$whatiwant = $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
$full_link = "http://" . $_SERVER[HTTP_HOST] . $_SERVER[REQUEST_URI];
Just try with:
$_SERVER['REQUEST_URI']
it will returns you:
/helloworld.php?name=Dan
But if you do:
trim($_SERVER['REQUEST_URI'], '/')
you will get:
helloworld.php?name=Dan
Use the variable query string if available:
echo isset($_SERVER["QUERY_STRING"]) ? $_SERVER["QUERY_STRING"] : "";
If you want to get all the query strings from the URL. You can use this:
echo basename($_SERVER['REQUEST_URI']);
$_SERVER['REQUEST_URI']
will returned helloworld.php?name=Dan.
You can try print_r($_SERVER)
for getting more from SERVER variable.