I would like to become self-sufficient, and therefore do without services such as DNSDynamic and DYNDNS. And I don't like paying for services that I could do myself.
So here's the scenario - I have my main website hosted with a hosting company. I also have a home server with my music, etc. on it. But the problem is that my ISP (BT) does not offer consumers Static IP addresses.
I would like to have a subdomain of my main domain (which points to my main host) point to my home IP. This is done with a simple A record - which I have done myself.
This boils down to me wanting to make a PHP script (run by a cron job on my home server) to update the A records in cPanel to the current IP of my home server.
Here's some sample code - of course the bit that's missing is the API Code to communicate with cPanel, and I'd be very thankful to anyone who could fill in the gaps for me.
<?php
$current_ip = file_get_contents("http://mydomain.com/getip.php");
$username = "CPANEL_USERNAME";
$password = "CPANEL_PASSWORD";
$domain = "CPANEL_DOMAIN";
$request = file_get_contents("http://someapipage?username=".$username."&pw=".$password."&domain=".$domain."&ip=".$current_ip);
?>
The code in http://mydomain.com/getip.php
is something along the lines of simply
<?php echo $_SERVER["REMOTE_ADDR"]; ?>
I already have the grasp of how to set up a cron job, as my home server is running Ubuntu, and I have read tutorials that call my cron.php
in my localhost directory using wget
.
I have tried this link but I couldn't fathom what he was doing. Thanks in advance.
$CPANEL_DOMAIN = 'https://mydomain.com:2083/';
(for secure access) and$core_domain = 'mydomain.com';
plus the first block of code. Tryprint_r($response); ?>
to see what you get, and to lead you to working the rest of it out. The one thing missing is authentication to the cPanel system - you may need to log on, get a cookie, and supply it to future calls. That requires a "context" to be supplied tofile_get_contents
, which in turn requires a bit of research! – Hodge