Hi,
I've contacted some website administrators for their API, inreturn, they have asked for source IP to whitelist it so that only requests from that IP will be considered as legit (its ok even if its shared IP).

So, now the problem is how do i get ip of site. Being a PHP developer, I've tried gethostbyname() which gives random ip's & also $_SERVER['REMOTE_ADDR'] (called from other server) which always gives the single IP. I'm totally confused with this & also, I've very less time to give them my source IP.

I don't have paid hosting. I always use, free tiers of appfog (.aws.af.cm) & openshift (-name.rhcloud.com). It would be great if someone can tell me process for finding any of those IP address or show me a way to get static IP(which i could share with them) for free or anyother host. Also,they have given permission to use this api only for 10days. Thanks in advance.

Dani AI

Generated

Quick clarification and practical steps (ties to posts by , and ).

What the API owner needs is the public IP that outbound requests originate from (the egress/public source IP). That is not the same as a visitor's IP or an app’s internal/listening address. has already highlighted the visitor-IP vs server-IP confusion; ’s OpenShift note about environment variables applies to the app’s bind/listen address, which often differs from the public egress address on PaaS platforms.

How to check the actual outbound IP from the running app
Run a simple outbound HTTP request from the app to an IP-echo service and record the response. Example (PHP):

<?php
// prints the public IP used for outbound HTTP requests
echo trim(@file_get_contents('https://api.ipify.org'));

Options to make the source IP stable for whitelisting

  • Confirm with the hosting provider whether outbound requests come from a fixed IP or a pool; request their published egress range if available.
  • Upgrade to a paid plan or reserved/static egress option if the provider offers it.
  • Place a small VPS or cloud VM with a static IP in front as a forward proxy / NAT gateway and route API calls through it (fast to set up and usually cheapest for a short window).
  • Use a VPN/proxy service that provides a guaranteed static exit IP.

Troubleshooting and cautions
PaaS/free tiers often use shared NAT/load-balancers and may have multiple or rotating egress addresses; whitelisting a single IP can break unexpectedly. If the API owner can, request a CIDR range or token-based alternative. Verify the actual egress IP during the same session that will make the API calls, and confirm with hosting support when possible (as suggested) before handing over the address.

Recommended Answers

All 2 Replies

Hi,

to be sure ask to the hosting support, regarding OpenShift check this link:

it seems you can get the listening IP by echoing few system variables:

  • OPENSHIFT_<cartridge>_IP
  • OPENSHIFT_<cartridge>_PORT

In practice from ssh run commands like these:

echo $OPENSHIFT_APPNAME_IP
echo $OPENSHIFT_APPNAME_PORT

Source:

So, now the problem is how do i get ip of site.

Do you mean the IP of the web server? That would need to be provided by the web server hosting/provider.

& also $_SERVER['REMOTE_ADDR']

If you are using this code in your web page, you are collecting the source iP of your web page visitor, not the web server itself.

So, to clarify, which IP address are you trying to get, the web visitor or the web server?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.