Php provides three methods to obtain the complete and real url address of the current page, including parameters. you can select the method as needed. the specific function code is as follows: the first method is functionGetCurUrl () {if (isset ($ _ SERVER [REQUEST_URI]) {$ url $ _ SERVER [REQUEST_URI];} else {if (isset ($ _ SERVER [argv]) {$ url $ _ S php obtains the complete and real url address of the current page, including parameters. three methods are summarized. you can select the method as needed. the specific function code is as follows:
Method 1:
Function GetCurUrl (){
If (isset ($ _ SERVER ['request _ URI ']) {
$ Url = $ _ SERVER ['request _ URI '];
} Else {
If (isset ($ _ SERVER ['argv']) {
$ Url = $ _ SERVER ['php _ SELF '].'? '. $ _ SERVER ['argv'] [0];
} Else {
$ Url = $ _ SERVER ['php _ SELF '].'? '. $ _ SERVER ['query _ string'];
}
}
Return urlencode ($ url); // pay attention to the encoding
}
The second method (it is said that the machine dream uses this method ):
// Obtain the current script URL
Function GetCurUrl (){
If (! Empty ($ _ SERVER ['request _ URI ']) {
$ ScriptName = $ _ SERVER ['request _ URI '];
$ Nowurl = $ scriptName;
} Else {
$ ScriptName = $ _ SERVER ['php _ SELF '];
If (empty ($ _ SERVER ['query _ string']) {
$ Nowurl = $ scriptName;
} Else {
$ Nowurl = $ scriptName .'? '. $ _ SERVER ['query _ string'];
}
}
Return $ nowurl;
}
Method 3 (recommended ):
// Php retrieves the complete url of the current access
Function GetCurUrl (){
$ Url = 'http ://';
If (isset ($ _ SERVER ['https']) & $ _ SERVER ['https'] = 'on '){
$ Url = 'https ://';
}
If ($ _ SERVER ['server _ port']! = '80 '){
$ Url. = $ _ SERVER ['server _ name']. ':'. $ _ SERVER ['server _ port']. $ _ SERVER ['request _ URI '];
} Else {
$ Url. = $ _ SERVER ['server _ name']. $ _ SERVER ['request _ URI '];
}
Return $ url;
}