Skip to content

Instantly share code, notes, and snippets.

@cypres
Created September 18, 2011 18:32
Show Gist options
  • Save cypres/1225364 to your computer and use it in GitHub Desktop.
Save cypres/1225364 to your computer and use it in GitHub Desktop.
find ip via php
<?php
// Uses third party site ipnr.dk, thanks a lot
if (isset($_SERVER["SERVER_ADDR"])) echo "Local Address: ".$_SERVER["SERVER_ADDR"]."<br/>\nRemote: ";
if (extension_loaded('curl')) {
$c = curl_init('http://ipnr.dk/');
curl_setopt($c,CURLOPT_USERAGENT,'curl/0 (PHP) libcurl/0');
curl_exec($c);
} else {
echo "no cURL extension\n";
}
if (extension_loaded('http')) {
$req = new HttpRequest('http://ipnr.dk/',HTTP_METH_GET,array('useragent'=>'curl/0 (PHP) libcurl/0'));
$req->send();
echo $req->getResponseBody();
} else {
echo "no http extension\n";
}
if (ini_get('allow_url_fopen') == true) {
ini_set('user_agent','curl/0 (PHP) libcurl/0');
echo file_get_contents('http://ipnr.dk/');
} else {
echo "no url fopen\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment