PHP Get URL with Parameter

后端 未结 5 1049
迷失自我
迷失自我 2021-02-01 15:45

I want to get a URL and its parameters. Example:

www.someweb.com/somepage.php?id=10

How to get only

相关标签:
5条回答
  • 2021-02-01 15:59

    Here's probably what you are looking for: php-get-url-query-string. You can combine it with other suggested $_SERVER parameters.

    0 讨论(0)
  • 2021-02-01 16:00

    $_SERVER['PHP_SELF'] for the page name and $_GET['id'] for a specific parameter.

    try print_r($_GET); to print out all the parameters.

    for your request echo $_SERVER['PHP_SELF']."?id=".$_GET['id'];

    return all the parameters echo $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];

    0 讨论(0)
  • 2021-02-01 16:05
    function curPageName() {
     return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
    }
    echo "The current page is ".curPageName()."?".$_SERVER['QUERY_STRING'];
    

    This will get you page name , it will get the string after the last slash

    0 讨论(0)
  • 2021-02-01 16:12

    for complette URL with protocol, servername and parameters:

     $base_url = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on' ? 'https' : 'http' ) . '://' .  $_SERVER['HTTP_HOST'];
     $url = $base_url . $_SERVER["REQUEST_URI"];
    
    0 讨论(0)
  • 2021-02-01 16:13

    Finally found this method:

    basename($_SERVER['REQUEST_URI']);
    

    This will return all URLs with page name. (e.g.: index.php?id=1&name=rr&class=10).

    0 讨论(0)
提交回复
热议问题