Version update checker script

Posted By: Ian on Jan 31, 2015 in PHP, Snippets

How can i get my script to check my site for updates?

The script below checks the local version number against the remote one and if the local is lower than the remote it shows the update link else just shows the current version number.
/* local script version */
define('version', '2.1.0');
* Version Checker
function check_version()
/* if cURL is available, use it */
if (function_exists('curl_init')) {
$ch = curl_init($REMOTE_VERSION_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$REMOTE_VERSION = curl_exec($ch);
} else {
/* if cURL is not available, use file_get_contents() */
/* if local version is less than remote version show update link */
if (version_compare(version, $REMOTE_VERSION, '<')) {
return "Version " . version . "&nbsp;&#124;&nbsp;<a href=\"\" title=\"Opens in New Window\" onclick=\";return false;\"><span class=\"external\">New Version Available</span></a>";
} else {
/* return local version number */
return "Version " . version;
print check_version();




Did this help you? Please Let me know by commenting below even if it’s just to say “Thanks”

leave a comment

About This Site

Dreams are built from lines of code well it's true!
If you can dream it you can usually code it.

I have learned so much from other people on the Internet and this site is for me to give back some of what i have learned and hope people can now learn from me.
Have fun and surf safely,

protected by copyscape duplicate content check


Powered by Banner Bar 125