charlestonolaes — 2011-07-15T19:55:08-04:00 — #1
this is purely an academic question.
question: What is the best way to handle version checking in php.
example: Let's say I have a CMS like script and so does other users, and I have the version number defined somewhere in the script, and on a certain page, it should compare the current version number with the version hosted on my server or a SVN/GIT repo.
I'm not looking for an entire script, I just need someone to point me in the right direction to find the "best"/most recommended practice.
like is it possible to get data off a specific URL on a different server? or is it better to do this via ajax and just print the version number in a hidden field?
dan_grossman — 2011-07-16T01:07:10-04:00 — #2
What kind of half-baked language would PHP be if it couldn't make network connections? Here's an example:
$version = file_get_contents("http://www.example.com/script-that-returns-current-version-number.php");
if ($version != CURRENT_VERSION)
echo "You need to upgrade. You're running version " . CURRENT_VERSION . " but the current version of this script is $version.";
That's all there is to it.
chris_upjohn — 2011-07-16T02:43:19-04:00 — #3
Personally i like using mod_rewrite to spoof a URL to the version tracker so the url would be something like "example.com/version.json" but really it would link to the file like Dan Grossman showed in his example above.
charlestonolaes — 2011-07-16T02:54:30-04:00 — #4
@Dan Grossman Oh cool, I never would have thought it was that simple. Here I was thinking that there was some magic library or class or whatever that I'll have to download... haha thanks for the info.