How do I get the external IP of my server using PHP?
Just query a host that returns your IP address:
$externalContent = file_get_contents('http://checkip.dyndns.com/');
preg_match('/Current IP Address: \[?([:.0-9a-fA-F]+)\]?/', $externalContent, $m);
$externalIp = $m[1];
or, set up a service that simply echoes just the IP, and use it like this:
$externalIp = file_get_contents('http://yourdomain.example/ip/');
Set up the service yourself by simply echoing the remote IP address, or pay someone to host it. Do not use somebody else's server without permission. Previously, this answer linked to a service of mine that's now being hit multiple times a second.
Note that in an IP network with one or more NATs, you may have multiple external IP addresses. This will give you just one of them.
Also, this solution of course depends on the remote host being available. However, since there is no widely implemented standard (no ISP and only some home routers implement UPnP), there is no other way to get your external IP address. Even if you could talk to your local NAT, you couldn't be sure that there isn't another NAT behind it.
how to get public ip address of my localhost system
try this please:
$externalContent = file_get_contents('http://checkip.dyndns.com/');
preg_match('/Current IP Address: \[?([:.0-9a-fA-F]+)\]?/', $externalContent, $m);
$externalIp = $m[1];
Or use httpbin.org/ip as Priyesh Kumar suggests
How can I connect to a database on an external ip?
First Check Your Public IP Address [ Public Ip Means External Ip Address
] From Here : https://www.whatismyip.com/
And Now Check Your System Ip Address ( Internal Ip Address using ipconfig in cmd
)
Both Are Differect So You Need To Used Public Ip Address
Which One You Get From https://www.whatismyip.com
Now, you have to Give Access permission to Database for Specific iP Address, By Default Mysql is not allowing to Access it SO You Need To Fire This Command for .
Like This :
SQL> GRANT ALL PRIVILEGES ON database.* TO 'user'@'your_database_pc_public_ip' IDENTIFIED BY 'newpassword';
Example::
SQL> GRANT ALL PRIVILEGES ON database.* TO 'any_name'@'public_ip' IDENTIFIED BY 'any_password';
Then Its Work Fine For You :)
PHP - Get the public ip
Try using $_SERVER['REMOTE_ADDR']
to fetch the user's IP address.
http://php.net/manual/en/reserved.variables.server.php
How do I get the external IP address in a Symfony2 controller?
I hate to answer my own question, and will gladly mark a better answer (short and elegant and independent of outside servers unlike below, maybe using the network stack, traceroute or some such wizardry), but for now for a task this small we needed something quick for staging or production, so:
$CustomerIp = system("curl -s ipv4.icanhazip.com") ; // returns string '93.9.29.389' (length=11)
Related Topics
Ios7 - Receipts Not Validating at Sandbox - Error 21002 (Java.Lang.Illegalargumentexception)
Differencebetween $_Server['Request_Uri'] and $_Get['Q']
How to Extract a String from Double Quotes
How to Get PHP, Symlinks and _File_ to Work Together Nicely
How to Get User Image with Twitter API 1.1
How to Convert Multiple <Br/> Tag to a Single <Br/> Tag in PHP
Multidimensional Array to String
Laravel Many to Many Self Referencing Table Only Works One Way
Can't Insert Russian Text into MySQL Database
Array Combine Three or More Arrays with PHP
PHP Get How Many Days and Hours Left from a Date
How to See the Actual Xml Generated by PHP Soap Client Class
A _Construct on an Eloquent Laravel Model
Htmlpurifier Iframe Vimeo and Youtube Video
PHP Switch Case More Than One Value in the Case
How to Use Curl to Fetch Specific Data from a Website and Then Save It My Database Using PHP