How can php determine the client IP address in each request?

Source: Internet
Author: User
How can php determine the client IP address in each request? We need to perform IP address verification for each request, that is, to identify whether the IP address has changed after the user logs on.
I want to implement it in PHP_RINIT_FUNCTION on the c layer, but I cannot find an interface in the C library that can get the client IP address.
The php layer can be obtained through $ _ SERVER ['remote _ add'], but the php code does not have a unified entry, so it is necessary to ADD judgment to all existing html, php, and js.

Could you please advise me if I have any good solutions to implement this function?


Reply to discussion (solution)

But HTTP_REMOTE_ADD is the environment variable of CGI gateway. php only places it in $ _ SERVER ['remote _ add '].
C can naturally be obtained.

But HTTP_REMOTE_ADD is the environment variable of CGI gateway. php only places it in $ _ SERVER ['remote _ add '].
C can naturally be obtained.


Thanks to the moderator for replying, does php provide the C interface? Or which part of the php code is involved?

Isn't your C php code? What else can I get with $ _ SERVER ['remote _ add?

Isn't your C php code? What else can I get with $ _ SERVER ['remote _ add?


After all, PHP code cannot be directly called in PHP_RINIT_FUNCTION in Part c, but the c interface is still required.
After reading the php source code, you can find the value of $ _ SERVER ['remote _ add'] through zend hash. Done.
Thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.