0

My current address is: http://localhost/bookstore/bookedit.php?book_id=12

The $_SERVER['PHP_SELF'] variable is a string '/bookstore/bookedit.php',

But I would like to get the string 'bookedit.php?book_id=12',

Do we have any function or variable can do this?

Thanks!

Charles
  • 50,943
  • 13
  • 104
  • 142
Eathen Nutt
  • 1,433
  • 5
  • 19
  • 27
  • 1
    Note that [PHP_SELF is vulnerable to XSS](http://stackoverflow.com/questions/6080022/php-self-and-xss), `$_SERVER['SCRIPT_NAME']` is a more secure alternative. – Fabian Schmengler Mar 22 '13 at 15:00
  • Following link contains all the information you need... http://php.net/manual/en/reserved.variables.server.php – Populus Mar 22 '13 at 14:58

3 Answers3

4

If you do a var_dump($_SERVER) you will see all of the server variables you have available to you

$_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
John Conde
  • 217,595
  • 99
  • 455
  • 496
  • wow, thanks for mentioning var_dump($_SERVER), first time to hear about it, it is very useful for the beginner like me! – Eathen Nutt Mar 22 '13 at 15:00
1

You can use the Request URI variable.

$_SERVER['REQUEST_URI']

Jared
  • 12,406
  • 1
  • 35
  • 39
0
$data = basename($_SERVER['PHP_SELF']);
$data .= $_SERVER['QUERY_STRING'] ? '?' . $_SERVER['QUERY_STRING'] : '';
sean662
  • 696
  • 6
  • 15