Code Samples

Updating DNS entries using the cPanel API

A client in Asia used an internet service provider that resets router connections every 24 hours and reassigns dynamic IP addresses. A dedicated IP address wasn't justified for this small office, yet traveling web designers did need to reference resources on a server hosted in the office.

The office has a web hosting plan that included DNS management through cPanel. Pulling together some sample code from around the web and with a fair amount of trial-and-error, we developed a script to query the office external IP address every five minutes. If that address changed, we logged into the cPanel API to update the corresponding DNS entry.

Place the following PHP file on your public internet server at any convenient location (we suggest /adm/reflect.php). If you use a different location, be sure to update reflectLink in the script below. The script simply returns as text the requesting Internet address for every HTTP GET request.