March 17, 2012It’s hard trying to figure out a convenient way to show an update message to those who download and install your PHP applications. It’s even harder trying to do it without bringing down your site or theirs. One way of accomplishing this is by using Curl. You can use the functions below to help get you started:
// Define the current version of your PHP Application.
define("CUR_VERSION",'2.1');
// Where the latest version of your PHP application is defined.
define('PHP_APP_URL', 'http://mydomain.com/latestversion.txt');
// Checks the remote server for the current version of your PHP application.
function get_latest_version($file) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$file);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
// Prints an update message if the installed version is less than the current version.
function show_update_message() {
if($_SESSION['level'] == 1) {
if(CUR_VERSION < get_latest_version(PHP_APP_URL)) {
echo 'Now all you need to do is figure out where you want the update message to appear and add the following line to your PHP application:
< ?php show_update_message(); ?>