Jump to content

Remote IP over HTTPS


ryanschefke

Recommended Posts

Hello,

 

I am trying to collect an IP address using PHP over both http and https connections. Does anyone know how I can collect the IP over https? I use the

 

$ip = $_SERVER['REMOTE_ADDR'];

 

...over http and it works just fine. However, when I use it over https it does not.

 

Thank you very much,

Ryan

Link to comment
Share on other sites

Hi Folks - I used the phpinfo() approach and ran it under http and https. To prove my point, check this out: http://www.leadliaison.com/phpinfo.php  -COMPARED TO- the same script under https, http://www.leadliaison.com/phpinfo.php. At the end you will see the server variables. It does not report the remote IP under https. Is there a solution here to collect the IP under https?

Link to comment
Share on other sites

The information shown in the phpinfo() output is ALL the information that your web server/php receives with each request.

 

Your web server is apparently behind a proxy server, which is setting the $_SERVER["HTTP_X_FORWARDED_FOR"] header. I expected this to also be set for the https request. I would speak to the server administrator and see what he/they can do about getting the $_SERVER["HTTP_X_FORWARDED_FOR"] header passed through with the https request. 

Link to comment
Share on other sites

Sorry, I must correct my last post:

 

http://www.leadliaison.com/phpinfo.php  -COMPARED TO- the same script under https,

https://www.leadliaison.com/phpinfo.php.

 

I am sure you figured that out though. The main issue seems to be that $_SERVER["HTTP_X_FORWARDED_FOR"] passes through under http but that server variable does not show up under https. I will chat with our server admin team about getting the $_SERVER["HTTP_X_FORWARDED_FOR"] header passed through with the https request.

 

Open to other ideas in the interim...

Link to comment
Share on other sites

Here is something I found that seems relevant -

# If the apache server is configured with "performance cache enabled" (default with Mac OS0X), it may return the Host-IP rather than the Client-IP. The Performance Cache can be disabled in ServerAdmin -> Web ->Settings->Options

# With old versions of apache (1.3.xx) you need to use an extra module (mod_proxy_add_forward) on the server which runs a proxy, to get the HTTP_X_FORWARED_FOR variable in the http header. With Apache 2.0 mod_proxy this is not anymore necessary, as it is included by default.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.