Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 如何获取请求服务器的IP

如何获取请求服务器的IP

Jun 23, 2016 pm 02:14 PM

我A服务器上有a.php,然后用B服务器上的b.php传参给a.php,如何让a.php知道B的IP地址,谢谢


回复讨论(解决方案)

$_SERVER['REMOTE_ADDR'] 获取请求方的IP

$_SERVER['REMOTE_ADDR'] 获取请求方的IP
试过了 这个只能取当前打开浏览器的电脑的IP,我的请求是程序在后台发的

你如何请求 b.php 的?

你如何请求 b.php 的?
file_get_contents

gethostbyname 得到指定的Internet主机名对应的IP地址
例:
echo gethostbyname('bbs.csdn.net'); //117.79.157.198

gethostbyname 得到指定的Internet主机名对应的IP地址
例:
echo gethostbyname('bbs.csdn.net'); //117.79.157.198
我想只让指定的主机IP访问,你这样只能获得某一台IP,但我不知道对方是哪台服务器在提交申请

我A服务器上有a.php,然后用B服务器上的b.php传参给a.php,如何让a.php知道B的IP地址,谢谢
$_SERVER[SERVER_ADDR]


我A服务器上有a.php,然后用B服务器上的b.php传参给a.php,如何让a.php知道B的IP地址,谢谢
$_SERVER[SERVER_ADDR]
这个取到的还是B服务器的IP啊,我要取A服务

本帖最后由 xuzuning 于 2013-07-01 16:01:52 编辑

#0: 如何让a.php知道B的IP地址
#8: 还是B服务器的IP啊,我要取A服务

你先想清楚了再提问!

#0: 如何让a.php知道B的IP地址
#8: 还是B服务器的IP啊,我要取A服务

你先想清楚了再提问!
不好意思 隔了三天我搞错了 ,是A要取B的地址 = = $_SERVER[SERVER_ADDR]以上方法要建立在B服务器把IP传给A的情况下才成功,但是对方能传假的值

那用 gethostbyname 取得的 ip 为什么就不行呢?

那用 gethostbyname 取得的 ip 为什么就不行呢?
我是一个充值平台,我为了防止合作商私下接入所以要规定白名单 只有白名单里的IP请求才有效,这样。。

gethostbyname 的参数是域名,返回的是相应的主机的ip
如果连这个都不可信的话,那我就无语了

gethostbyname 的参数是域名,返回的是相应的主机的ip
如果连这个都不可信的话,那我就无语了
这个是可信的,不用这个的原因是我知道某IP肯定是我们的合作商,但是要是第三方介入的话 我既不知道他的域名也不知道他的IP 就没法判断了


你如何请求 b.php 的?
file_get_contents 我既不知道他的域名也不知道他的IP 
那你怎么 file_get_contents ?



你如何请求 b.php 的?
file_get_contents 我既不知道他的域名也不知道他的IP 
那你怎么 file_get_contents ?
这句是写在B服务器上的 ,这台服务器不是我的,所以要是靠他传值的话 不能确定真假,要从我自己的服务器A获取B的请求地址才行

亲,file_get_contents可以在A机器上获取B的地址的,这个函数还可以用来判断一个域名是不是真的存在

上面说错了,是gethostbyname函数

上面说错了,是gethostbyname函数 这函数前提是你要知道对方的域名呀 ,现在我不知道请求方的域名

那一般就是看$_SERVER变量的REMOTE_ADDR,HTTP_X_FORWARDED_FOR,HTTP_CLIENT_IP,HTTP_X_FORWARDED_FOR这些参数了

那一般就是看$_SERVER变量的REMOTE_ADDR,HTTP_X_FORWARDED_FOR,HTTP_CLIENT_IP,HTTP_X_FORWARDED_FOR这些参数了 所以说使用哪个。。。我不是很熟

继续求。。。。。。

好的 。。。找到原因了 谢谢楼上各位

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

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

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)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

See all articles