Among the many predefined SERVER variables in PHP, $ _ SERVER [REQUEST_URI] is frequently used, but this variable is only supported by apache. Therefore, we need a more general method to obtain the value of REQUEST_URI. This article is the solution to this problem.
Among the many predefined SERVER variables in PHP, $ _ SERVER [REQUEST_URI] is frequently used, but this variable is only supported by apache. Therefore, we need a more general method to obtain the value of REQUEST_URI. This article is the solution to this problem.
The Code is as follows:
// Description: gets the value of _ SERVER ['request _ URI '].
Function request_uri ()
{
If (isset ($ _ SERVER ['request _ URI '])
{
$ Uri = $ _ SERVER ['request _ URI '];
}
Else
{
If (isset ($ _ SERVER ['argv'])
{
$ Uri = $ _ SERVER ['php _ SELF '].'? '. $ _ SERVER ['argv'] [0];
}
Else
{
$ Uri = $ _ SERVER ['php _ SELF '].'? '. $ _ SERVER ['query _ string'];
}
}
Return $ uri;
}
?>