Dynamic IP and cron job

I have a script.php which is used to update the IP address of my domain on registrar's website. I keep it on /etc/. The IP address of the server only changes on connection. Please advise how to create a "cron job" which will run the script after booting to update the IP address.

1) Basically you create the script in /etc/init.d/ip_update
2) Make it executable
3) Symlink it to the according runlevels (on that website the K means as much as Kill and S means as much as Start... the number is the sequence of starting/killing in that runlevel)

The script.php was download from the site where I registered the domain. I don't think they allow third party program. There is a short instruction on the file download instructing running the script.php on cron.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////BRIEF OVERVIEW PLEASE READ //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//*
//*
//* This script will update your dynamic ip address by the use of a cron job. There are two ways this script can
//* be used.
//*
//* 1. No Router, This is if your PC Running Linux is connected directly to your ISP. Using this setup option will
//* allow you to set the cron job to run every few minutes. Only when your IP changes an update will be sent.
//*
//* NOTE: IF YOUR CRON JOB IS SET TO EVERY FEW MINUTES SET YOUR EMAIL OPTIONS TO "0" Or you will fill the log file
//* along with your email box.
//*
//* 2. Router, - snip -
//*
//* NOTE: If you are on a CABLE MODEM or DSL your IP
-snip-
//* IF YOUR CRON JOB IS SET TO EVERY FEW MINUTES SET YOUR EMAIL OPTIONS TO "0" Or you will fill the log file
//* along with your email box.
//*
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////CHECK YOUR CHANGEIP.COM SETTINGS ////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

//* 1. Make Changes to your domains so that ALL Options update on SET 1. The first column of check boxes.
//*
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////// SETUP INSTRUCTIONS ///////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//*
//* 1. Edit the variables below in this file to match your server and your needs.
//* 2. Upload update.php and updatedns.log to your root web.
//* 3. chmod updatedns.log to 666
//* 3. Create a cron job to execute update.php. See the following example.
//*
//* Telnet into your server create a new cronjob. The following would
//* run every night at 12:59pm. Depending on your needs you will have
//* to modify the run time variables.
//*
//* 59 23 * * * wget -q http://www.yoursite.com/update.php
//*
//* minute (0-59)
//* hour (0-23)
//* day of the month (1-31)
//* month of the year (1-12)
//* day of the week (0-6 with 0=Sunday)
//*
//* NOTE: A cron can also be setup using WEBMIN if you have it installed. This is easyier for most.
//*
//*
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////// SETUP OPTION DESCRIPTIONS DO NOT EDIT THESE HERE //////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

//* $username = "changeip.com login username";
//* $password = "changeip.com login password";
//*
//* $Adminemail = "[email protected]";
//* $Sendmail = "/path/to/sendmail -t -i";
//*
//* $Logfile = "/full/server/path/to/updatedns.log";
//*
//*
////////////////////////////////////////// IF USING A ROUTER ////////////////////////////////////////////////
-snip-
////////////////////////////////////// NO ROUTER, DIRECT CONNECTION /////////////////////////////////////////
//*
//*
//*
//* $Log1 = "0"; No log file output
//* $Log1 = "1"; Appends a new line to the log file ONLY when a update is sent to changeip.com
//* $Log2 = "0"; No log file output
//* $Log2 = "1"; Appends a new line to the log file even when there is no update sent to changeip.com
//* $Email1 = "0"; No Email Will be sent
//* $Email1 = "1"; Sends an email to the address specified. when a update is sent to changeip.com
//* $Email2 = "0"; No Email Will be sent
//* $Email2 = "1"; Sends an email to the address specified. when a update is sent to changeip.com
//*
//* $IPfile = "/full/server/path/to/updatednsIP.log"; <--- This is not an option if using direct connect
//* $Logfile = "/full/server/path/to/updatedns.log";
//*
//*
//*
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////<-------- EDIT USER VARIABLES HERE --------> ////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////<--------- END USER VARIABLES --------> /////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING//////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

$to = "$Adminemail";
$subject = "IP Auto update Report";
$body ="Hello, $username\r\n\r\nYour IP address has changed and an update request was sent to changeip.com.\r\n\r\n Current IP: $REMOTE_ADDR\r\n Previous IP: Either this is the first time you run this script or you deleted the updatednsip.log. This is normal\r\n Time: $tdate\r\n Date: $datecode\r\n\r\nChangeip.com IP Auto Updater by [email protected]";

Just get lynx (a text based browser) and then do a call of your php script through lynx... alternatively you can setup a cron where you invoke the php binary with the php script but right now I have no clue how to do that

-t Read message for recipients. To:, Cc:, and Bcc: lines will be
scanned for recipient addresses. The Bcc: line will be deleted
before transmission.
-i Ignore dots alone on lines by themselves in incoming messages.
This should be set if you are reading data from a file.

On console/terminal
$ sudo php /usr/local/bin/update.php

Code:

Warning: file() expects parameter 2 to be long, string given in /usr/local/bin/update.php on line 183
Warning: Invalid argument supplied for foreach() in /usr/local/bin/update.php on line 184

Of course you would have to move your domain to this registrar (that is: registration in DNS), which I did some years ago and I'm totally satisfied. Even their support is great, wonder how they do it for such a low price. They also provide a very good and affordable MX backup service, which you will probably need.

I've installed the script (slightly modified) as a cron job, works perfectly!