本文实例讲述了php获取客户端IP及URL的方法。分享给大家供大家参考,具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
function getonlineip(){ //获取用户ip
if ( $_SERVER [ 'HTTP_CLIENT_IP' ])
{
$onlineip = $_SERVER [ 'HTTP_CLIENT_IP' ]; //用户IP
}
else if ( $_SERVER [ 'HTTP_X_FORWARDED_FOR' ])
{
$onlineip = $_SERVER [ 'HTTP_X_FORWARDED_FOR' ]; //代理IP
}
else
{
$onlineip = $_SERVER [ 'REMOTE_ADDR' ]; //服务器IP
}
return $onlineip ;
}
function curPageURL() //获取完整的url
{
$pageURL = 'http' ;
if ( $_SERVER [ "HTTPS" ] == "on" )
{
$pageURL .= "s" ;
}
$pageURL .= "://" ;
if ( $_SERVER [ "SERVER_PORT" ] != "80" )
{
$pageURL .= $_SERVER [ "SERVER_NAME" ] . ":" . $_SERVER [ "SERVER_PORT" ] . $_SERVER [ "REQUEST_URI" ];
}
else
{
$pageURL .= $_SERVER [ "SERVER_NAME" ] . $_SERVER [ "REQUEST_URI" ];
}
return $pageURL ;
}
|
希望本文所述对大家PHP程序设计有所帮助。