search
Homephp教程PHP源码任何地方获取用户的登陆ip地址

任何地方获取用户的登陆ip地址

后台就有这功能.虽然简单,但是很多人,开发的时候都没开发过.音乐$_SERVER['']这个代码引导的.其实他不能获取任何网络来源的ip

网易 
博客 
GACHA-脖子以下全是腿的妹子
LOFTER-柳岩新电影竟全裸出镜
印像派-儿童节61折
 
颜值最高的图片社交APP >
注册
登录
 
 加关注
【开源与分享】每日最新博客在置顶博客之后

博客已搬家,请大家访问博主新家:http://www.blogdaren.com

    首页
    日志
    LOFTER
    相册
    音乐
    收藏
    博友
    关于我

 
 
日志
 
 
关于我
PHP网站开发

VIM发烧友-面向对象编程OOP-迷人的火狐插件
  加博友   关注他
文章分类

    ·我做的美食哇(4)
    ·IOS/SWIFT(1)
    ·IT拾趣(2)
    ·吉他王国(2)
    ·qeephp专区(7)
    ·VIM专区(13)
    ·python(2)
    ·Linux/Unix(813)
    ·更多 >

LOFTER精选
注册免费冲印20张照片 >
网易考拉推荐
网易新闻
高考在即:学生与老师掰手腕减压

    ·铲车司机街头撞人被当场击毙
    ·准妈妈怀孕7个月查出铅中毒
    ·大伯仰头喝可乐突然四肢瘫痪
    ·女子信"偏方" 猛吃海带患甲亢
    ·湖北神农架降雪 高山杜鹃披冰甲
    ·台媒曝大S产前癫痫发作内幕
    ·中学校长毕业致辞:大学要恋爱
    ·村民举报盗金者:曾遭矿主威胁

下载网易新闻客户端 >
 
Chrome 稳定版 更新至 27.0.1453.116
 
Windows下访问Linux分区的工具[译]
PHP获取用户访问IP地址的5种方法  

2013-06-20 23:07:51|  分类: php |举报 |字号 订阅
       

  下载LOFTER
我的照片书  |
这里的博客停止维护,请大家点下方的链接访问博主新家对应的博文:http://www.blogdaren.com/post-349.html这里的博客停止维护,请大家点下方的链接访问博主新家对应的博文:http://www.blogdaren.com/post-349.html这里的博客停止维护,请大家点下方的链接访问博主新家对应的博文:http://www.blogdaren.com/post-349.html这里的博客停止维护,请大家点下方的链接访问博主新家对应的博文:http://www.blogdaren.com/post-349.html这里的博客停止维护,请大家点下方的链接访问博主新家对应的博文:http://www.blogdaren.com/post-349.html今天再来总结下PHP获取用户访问IP地址的5种方法:

<?php                                                                                                                                 //方法1:
$ip = $_SERVER["REMOTE_ADDR"];
echo $ip;

//方法2:
$user_IP = ($_SERVER["HTTP_VIA"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"];
$user_IP = ($user_IP) ? $user_IP : $_SERVER["REMOTE_ADDR"];
echo $user_IP;

//方法3:
function getRealIp()
{
    $ip=false;
    if(!empty($_SERVER["HTTP_CLIENT_IP"])){
        $ip = $_SERVER["HTTP_CLIENT_IP"];
    }
    if (!empty($_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;])) {
        $ips = explode (", ", $_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;]);
        if ($ip) { array_unshift($ips, $ip); $ip = FALSE; }
        for ($i = 0; $i < count($ips); $i++) {
            if (!eregi ("^(10│172.16│192.168).", $ips[$i])) {
                $ip = $ips[$i];
                break;
            }
        }
    }
    return ($ip ? $ip : $_SERVER[&#39;REMOTE_ADDR&#39;]);
}
echo getRealIp();

//方法4:
if ($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"])
{
    $ip = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];
}
elseif ($HTTP_SERVER_VARS["HTTP_CLIENT_IP"])
{
    $ip = $HTTP_SERVER_VARS["HTTP_CLIENT_IP"];
}
elseif ($HTTP_SERVER_VARS["REMOTE_ADDR"])
{
    $ip = $HTTP_SERVER_VARS["REMOTE_ADDR"];
}
elseif (getenv("HTTP_X_FORWARDED_FOR"))
{
    $ip = getenv("HTTP_X_FORWARDED_FOR");
}
elseif (getenv("HTTP_CLIENT_IP"))
{
    $ip = getenv("HTTP_CLIENT_IP");
}
elseif (getenv("REMOTE_ADDR"))
{
    $ip = getenv("REMOTE_ADDR");
}
else
{
    $ip = "Unknown";
}
echo $ip ;

//方法5:
if(getenv(&#39;HTTP_CLIENT_IP&#39;)) {
    $onlineip = getenv(&#39;HTTP_CLIENT_IP&#39;);
} elseif(getenv(&#39;HTTP_X_FORWARDED_FOR&#39;)) {
    $onlineip = getenv(&#39;HTTP_X_FORWARDED_FOR&#39;);
} elseif(getenv(&#39;REMOTE_ADDR&#39;)) {
    $onlineip = getenv(&#39;REMOTE_ADDR&#39;);
} else {
    $onlineip = $HTTP_SERVER_VARS[&#39;REMOTE_ADDR&#39;];
}
echo $onlineip;  
阅读(11572)| 评论(0)
       

喜欢 推荐 转载
 
Chrome 稳定版 更新至 27.0.1453.116
 
Windows下访问Linux分区的工具[译]
历史上的今天

    使用DNSCrypt解决DNS污染问题2014-06-20 13:23:06
    如何对MySQL中的大表进行数据归档2014-06-20 10:46:31
    php_memcache 压缩存储以及相关方法参数的完整定义2012-06-20 18:01:14
    LINUX如何批量复制文件?2012-06-20 14:25:32
    一款非常独特的4窗口资源管理器: Q-Dir2012-06-20 13:35:27

鸣人
zichunteng@126
zhengxiufei
a3866110
shyss
醉有英德
liyong824
13306013303
关闭
玩LOFTER,免费冲印20张照片,人人有奖!     我要抢>
评论
  登录后你可以发表评论,请先登录。登录>>
 
 
我的照片书 - 博客风格 - 手机博客 - 下载LOFTER APP - 订阅此博客

网易公司版权所有 ©1997-2016
加入网易博客
注册

2. [图片] 虾囧cms.png任何地方获取用户的登陆ip地址    

1210.png


                   

 以上就是任何地方获取用户的登陆ip地址的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment