PHP Get URL with Parameter

php
2022-08-30 13:16:22

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

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

How to get only ?somepage.php?id=10

I'm already tried and but it only gives me or . What I want to is just the page name and its parameter(s).REQUEST_URIPHP_SELFwww.someweb.com/somepage.phpsomepage.php


答案 1
basename($_SERVER['REQUEST_URI']);

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


答案 2

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"];

推荐