August 26, 2013

version update script for a script

Marlboroman213’s Question:

I’m going to try making this easy to understand and hope it makes sense.

I have a PHP script / template and I want the end user to be able to know when I updated something, (eg. template change or a bugfix) and they can click a link to download the updated version from a remote host. I tried the scripts posted on
PHP – How to check a script version and I sorta got this script working:

<?php define('REMOTE_VERSION', http://mysite.com/_client/client_name/update/version_check.txt');
    define('VERSION', '2.0.1');
    $script = file_get_contents(REMOTE_VERSION);
    $version = VERSION;
    if($version == $script) {
        echo "<div class=success> 
    <p>You have the latest version!</p> 
    </div>";
    } else {
        echo "<div class=error> 
    <p>There is a update available!</p> 
    </div>";
    }?>

Well sort of… The .txt file on my remote server just has 2.0.1. Since they are the same version (both 2.0.1), it should read “You have the latest version!” In this case it says “There is a update available!” no matter what number I put in.

define('VERSION', '2.0.1'); //in php above 

2.0.5 //in .txt file on remote server

Says same things as it should because on the remote server is showing a new update (eg. 2.0.5). Can anyone tell me what I am doing wrong?

This might be a typo, but there is an error at your constant definition.

define('REMOTE_VERSION', http://mysite.com/_client/client_name/update/version_check.txt');
                     // ^ Missing quote

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!