Page 1 of 2

check if app's "up-to-date"

Posted: Wed Feb 21, 2007 1:58 am
by tarja311
Hello all.

I was just wondering how forums like Invision check to see if you have the latest version of their forum or not? I would like to incorporate something like this into my own project but unsure how to do it exactly. So far i am only able to verify if the file exists using fopen().

Code: Select all

<?

$url = "http://myweb.com/file.zip";

if (fopen($url, "r")) 
    echo "The file exists.";
else
    echo "The file does not exist.";

?>
To make it more clearer, i am trying to add a "you are using the latest version ..." type of message by checking my website for the latest version of my web app.

Thanks

--tarja

Posted: Wed Feb 21, 2007 3:31 am
by onion2k
Personally, I'd use a "web service" type of system. On my site I'd have something that returns data about the latest version of the software, eg:

Code: Select all

<?php

    $version = "1";
    $subversion = "3";
    $release = "5";

    echo  $version."-".$subversion."-".$release;

?>
Then in the application I'd have a function that checks the version occasionally:

Code: Select all

function checkVersion() {

if (date("w")==1 and $checkedLatest!=date("Y-m-d")) { //Check for a new version on monday and if the last check wasn't today.
   if ($versionInfo = file_get_contents(LATEST_VERSION_URL)) { //Go and get the version data from my server
       list($version,$subversion,$release) = explode("-",$versionInfo); //Break the version data up
       if ($version!=VERSION or $subversion!=SUBVERSION or $release!=RELEASE) { //Check it against constants defined when the application runs
           echo "Your version is out of date!"; //Tell the user they ought to update
       }
        updateCheckedLatest(); //Something to store the last check date in Y-m-d format
    } else {
        echo "Could not download version information"; //Tell the user there was a problem
    }
}

}

Posted: Wed Feb 21, 2007 4:49 am
by Adrianc333
Here's the sort of thing i use.

Code: Select all

<?php
// By Adrian at http://dreamit.co.uk

$current_version = "1.0.1";

$version_check_file = file_get_contents("http://www.dreamit.co.uk/version_check_number.php") or die ("Sorry, there seems to be some problems reaching the version checking file.");

    if($version_check_file)
    {
        if($current_version < $version_check_file)
        {
            echo "You installation appears to be out-of date.<br />Your version: " . $current_version . "<br />Available version: " . $version_check_file . "";
            
        }
        else if($current_version >= $version_check_file)
        {
            echo "Your installation appears to be up-to date.";
        }
    }

?> 
In version_check_number.php, would just be the newest version number.
And, simply update the code aboce, with the script version number on every release. :)

Posted: Wed Feb 21, 2007 5:19 am
by the DtTvB
I would do this way:
  1. First, create a file on a webserver that contains the latest version of file...
    For example, http://example.com/latest.txt should contain something like 0.2 or something like that.
  2. Then, let the program connect to the server, for example,

    Code: Select all

    $currentVersion = '0.1';
    $latestURL = 'http://example.com/latest.txt';
    $latestVersion = file_get_contents($latestURL);
[*] Then, check if the $currentVersion and $latestVersion is the same.
If it's the same, it is the latest version, else it's not.
[/list]

Posted: Wed Feb 21, 2007 5:34 am
by onion2k
Seriously people, read the thread. There's no point in relying with exactly the same solution someone else has already posted. We've had the same thing 3 times now.

Posted: Wed Feb 21, 2007 8:14 am
by Mordred
I disagree, there are good and bad things in all the examples:

1. The version file should be static (as per the 3rd example), it is something rarely changes and there's no point in making a PHP to return a static string. Well, unless you want to go big brother on the app users of course ;)
2. The version check should not be run every time! Check onion2k's example for a possible solution. The returned version should be cached though.
3. The version check function should not print anything, but return true or false, printing is something of the caller's responsibility.

Just my 0.02 Euro

Posted: Wed Feb 21, 2007 8:24 am
by onion2k
Mordred wrote:1. The version file should be static (as per the 3rd example), it is something rarely changes and there's no point in making a PHP to return a static string. Well, unless you want to go big brother on the app users of course ;)
The version in my version is static: it's defined as constants. It's not defined in the version checking routine because constants shouldn't be defined in functions.
Mordred wrote:2. The version check should not be run every time! Check onion2k's example for a possible solution. The returned version should be cached though.
Caching the version number is a good idea. Then you could nag the admin to update every time they log in.
Mordred wrote:3. The version check function should not print anything, but return true or false, printing is something of the caller's responsibility.
Fair point.

Posted: Wed Feb 21, 2007 8:41 am
by Mordred
No, I meant the version file, the one in LATEST_VERSION_URL which is .php in your case. I feel it should be plain .txt, in case you have millions of installations that request the file and bring the server to its knees, and .... Well, not much point in it really, but it's marginally better ;)

Posted: Wed Feb 21, 2007 9:10 am
by onion2k
Mordred wrote:No, I meant the version file, the one in LATEST_VERSION_URL which is .php in your case. I feel it should be plain .txt, in case you have millions of installations that request the file and bring the server to its knees, and .... Well, not much point in it really, but it's marginally better ;)
I see what you mean. Well, if it were as simple as the code I posted then you'd be right, but I'd actually store all that sort of thing in a database table so it'd have to be PHP really.

Posted: Wed Feb 21, 2007 9:12 am
by Kieran Huggins
Mordred wrote:Just my 0.02 Euro
I thought the smallest Euro minted was 0.05 Euro...

Posted: Wed Feb 21, 2007 9:29 am
by onion2k
Kieran Huggins wrote:
Mordred wrote:Just my 0.02 Euro
I thought the smallest Euro minted was 0.05 Euro...
Some countries still have 1 and 2 euro cent coins.

Posted: Wed Feb 21, 2007 3:58 pm
by tarja311
Thanks guys. works like a charm.

Posted: Fri Feb 23, 2007 3:00 pm
by tarja311
Hey guys, i apologize for revisiting this thread but i have a question.

The file_get_contents function works flawlessly, but it only works internally/locally. I think my host, and mostly everyone elses host that use my app is blocking this function, as it does not externally connect to my server to check if the app is up to date or not.

I was just wondering if there is an alternative solution? My invision forum is running on my server and it seems to work fine, because just today, it notified me that there is an update available. lol

thanks.

-- tarja

Posted: Fri Feb 23, 2007 4:02 pm
by nickvd
tarja311 wrote:My invision forum is running on my server and it seems to work fine, because just today, it notified me that there is an update available.
Look at their code?

Posted: Fri Feb 23, 2007 10:47 pm
by tarja311
nickvd wrote:
tarja311 wrote:My invision forum is running on my server and it seems to work fine, because just today, it notified me that there is an update available.
Look at their code?
I have. It's too cryptic. The only thing remotely close to anything is this tiny snippet:

Code: Select all

$this->ipsclass->version = 'v'.$latest_version['upgrade_version_human'];
		$this->ipsclass->vn_full = ( isset($latest_version['upgrade_notes']) AND $latest_version['upgrade_notes'] ) ? $latest_version['upgrade_notes'] : $this->ipsclass->vn_full;
		
		$content['update_img'] = $this->html->update_img( IPS_VERSION_CHECK_URL . '?' . base64_encode( $this->ipsclass->vn_full.'|^|'.$this->ipsclass->vars['board_url'] ) );
where "IPS_VERSION_CHECK_URL" is a constant with the url to their remote update page.