PHP curl script to retrieve server IP

Use this script that will access ipecho.net from your server:

// create a new cURL resource
$ch = curl_init ();

// set URL and other appropriate options
curl_setopt ($ch, CURLOPT_URL, "http://ipecho.net/plain");
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);

// grab URL and pass it to the browser

$ip = curl_exec ($ch);
echo "The public ip for this server is: $ip";
// close cURL resource, and free up system resources
curl_close ($ch);

or use entire HTML page on root of your hosting, with same aproach:

<!DOCTYPE html>
<html>
<head>
    <title>Server IP</title>
</head>
<body>

<?php
// create a new cURL resource
$ch = curl_init ();

// set URL and other appropriate options
curl_setopt ($ch, CURLOPT_URL, "http://ipecho.net/plain");
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);

// grab URL and pass it to the browser

$ip = curl_exec ($ch);
echo "The public ip for this server is: $ip";
// close cURL resource, and free up system resources
curl_close ($ch);
?>
</body>
</html>