PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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().
<?
$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.
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
}
}
}
<?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.
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.
Then, let the program connect to the server, for example,
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.
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.
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.
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
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.
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
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.
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: