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

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

May 20, 2016 pm 12:58 PM

任何地方获取用户的登陆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
加入网易博客
注册
Copy after login

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

1210.png


                   

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

Statement of this Website
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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use Xiaohongshu account to find users? Can I find my mobile phone number? How to use Xiaohongshu account to find users? Can I find my mobile phone number? Mar 22, 2024 am 08:40 AM

With the rapid development of social media, Xiaohongshu has become one of the most popular social platforms. Users can create a Xiaohongshu account to show their personal identity and communicate and interact with other users. If you need to find a user’s Xiaohongshu number, you can follow these simple steps. 1. How to use Xiaohongshu account to find users? 1. Open the Xiaohongshu APP, click the &quot;Discover&quot; button in the lower right corner, and then select the &quot;Notes&quot; option. 2. In the note list, find the note posted by the user you want to find. Click to enter the note details page. 3. On the note details page, click the &quot;Follow&quot; button below the user's avatar to enter the user's personal homepage. 4. In the upper right corner of the user's personal homepage, click the three-dot button and select &quot;Personal Information&quot;

Local users and groups are missing on Windows 11: How to add it Local users and groups are missing on Windows 11: How to add it Sep 22, 2023 am 08:41 AM

The Local Users and Groups utility is built into Computer Management and can be accessed from the console or independently. However, some users find that local users and groups are missing in Windows 11. For some people who have access to it, the message suggests that this snap-in may not work with this version of Windows 10. To manage user accounts for this computer, use the User Accounts tool in Control Panel. The issue has been reported in previous iterations of Windows 10 and is usually caused by issues or oversights on the user's side. Why are local users and groups missing in Windows 11? You are running Windows Home edition, local users and groups are available on Professional edition and above. Activity

Log in to Ubuntu as superuser Log in to Ubuntu as superuser Mar 20, 2024 am 10:55 AM

In Ubuntu systems, the root user is usually disabled. To activate the root user, you can use the passwd command to set a password and then use the su- command to log in as root. The root user is a user with unrestricted system administrative rights. He has permissions to access and modify files, user management, software installation and removal, and system configuration changes. There are obvious differences between the root user and ordinary users. The root user has the highest authority and broader control rights in the system. The root user can execute important system commands and edit system files, which ordinary users cannot do. In this guide, I'll explore the Ubuntu root user, how to log in as root, and how it differs from a normal user. Notice

Explore Windows 11 guide: How to access user folders on your old hard drive Explore Windows 11 guide: How to access user folders on your old hard drive Sep 27, 2023 am 10:17 AM

Certain folders are not always accessible due to permissions, and in today’s guide we will show you how to access user folders on your old hard drive on Windows 11. The process is simple but can take a while, sometimes even hours, depending on the size of the drive, so be extra patient and follow the instructions in this guide closely. Why can't I access my user folders on my old hard drive? User folders are owned by another computer, so you cannot modify them. You don't have any permissions on the folder other than ownership. How to open user files on old hard drive? 1. Take ownership of the folder and change permissions Find the old user directory, right-click on it and select Properties. Navigate to "An

Tutorial: How to delete a normal user account in Ubuntu system? Tutorial: How to delete a normal user account in Ubuntu system? Jan 02, 2024 pm 12:34 PM

Many users have been added to the Ubuntu system. I want to delete the users that are no longer in use. How to delete them? Let’s take a look at the detailed tutorial below. 1. Open the terminal command line and use the userdel command to delete the specified user. Be sure to add the sudo permission command, as shown in the figure below. 2. When deleting, be sure to be in the administrator directory. Ordinary users do not have this permission. , as shown in the figure below 3. After the delete command is executed, how to judge whether it has been truly deleted? Next we use the cat command to open the passwd file, as shown in the figure below 4. We see that the deleted user information is no longer in the passwd file, which proves that the user has been deleted, as shown in the figure below 5. Then we enter the home file

Apple after-sales (apple after-sales point address) Apple after-sales (apple after-sales point address) Jan 11, 2024 pm 10:30 PM

Apple’s official after-sales phone number: Apple’s 24-hour service center phone number: 400-666-8800. The after-sales service telephone number for Apple mobile phones is: 400-666-8800. -627-2273. Apple’s customer service manual service hotline is 400-627-2273 for after-sales support; 400-666-8800 for the online store; and the only official Apple phone number is 400-666-8800. Apple's customer service hotline is 400-666-8800. You can call this number to inquire about hardware, software and third-party accessories of Apple products. It should be noted that Apple’s manual customer service does not provide services 24 hours a day. Their service hours are from 9 a.m. to 9 p.m. (Sundays are from 9 a.m. to 9 p.m.

What is sudo and why is it important? What is sudo and why is it important? Feb 21, 2024 pm 07:01 PM

sudo (superuser execution) is a key command in Linux and Unix systems that allows ordinary users to run specific commands with root privileges. The function of sudo is mainly reflected in the following aspects: Providing permission control: sudo achieves strict control over system resources and sensitive operations by authorizing users to temporarily obtain superuser permissions. Ordinary users can only obtain temporary privileges through sudo when needed, and do not need to log in as superuser all the time. Improved security: By using sudo, you can avoid using the root account during routine operations. Using the root account for all operations may lead to unexpected system damage, as any mistaken or careless operation will have full permissions. and

Windows 11 KB5031455 fails to install, causing other issues for some users Windows 11 KB5031455 fails to install, causing other issues for some users Nov 01, 2023 am 08:17 AM

Microsoft began rolling out KB2 to the public as an optional update for Windows 503145511H22 or later. This is the first update to enable Windows 11 Moment 4 features by default, including Windows Copilot in supported areas, preview support for items in the Start menu, ungrouping of the taskbar, and more. Additionally, it fixes several Windows 11 bugs, including potential performance issues that caused memory leaks. But ironically, the optional update for September 2023 will be a disaster for users trying to install the update, or even for those who have already installed it. Many users will not install this Wi

See all articles