Mandatory Update

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!

Moderator: General Moderators

Post Reply
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Mandatory Update

Post by SidewinderX »

I'm going to be releasing a script soon, and if i release an update I would like to make it mandatory. (but of course if the user knows php he can disable it, but it wouldnt be in his best interest)

My idea was to include this in the header file

Code: Select all

if($update == "YES"){
echo "You must upgrade to the latest version";
exit;
}
if $update is set to yes the script wouldnt run, only display "You must upgrade to the latest version." However my problem is how to set $update remotley. I tried something like this (lol) :oops:

Code: Select all

include("http://www.extreme-hq.com/include.php");
and have include.php had this

Code: Select all

<?php
$update = "NO"; //or YES
?>
but that didnt work. I suppose I could create a remote database connection, but im sure that introduces security issues. Is there any other way to do this?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Requesting a remote php file will return the executed php only. The script you tested would output nothing for php to use. I wouldn't even go that sort of road.

What I would suggest is an Ajax-like query in the administrative pages (if you have any.)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

You could echo a yes or no in your remote script and call it using curl or include, but keep in mind not all servers allow remote includes or have curl installed.
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post by SidewinderX »

what about reading from a remote text file?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

pretty much the same situation as astions has said.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Just remember that you shouldn't perform the check on every page-request.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

Also keep in mind that you need to have a version control system. It's not going to be easy as having a boolean.

Have some sort of system where the admin panel sends a query to the central server with a variable of the version.

http://example.com/needs_update.php?v=1.2.34

Where the 1.2.34 is the version of the script that wants to check whether it is the newest version or not.
Tom420
Forum Newbie
Posts: 15
Joined: Sun Aug 13, 2006 1:50 am
Location: Sherbrooke, Québec, Canada

Post by Tom420 »

I would do this way:

1) Have a text file available on the remote server containing just the file version of the new file.

A text file as the advantage that (as astions mentionned) it will work even if remote includes are disabled. The file could be generated from a PHP script if needed.

2) The local script would get the remote version file number at startup, but only once in a while. For exemple, once per day or once per week. That is because if the script checks for updates at every hit, it will 1) slow down the script a lot 2) overload the remote server if your script is popular.

On the oppsite to Todd_Z, I prefer the idea of the script deciding itself, from the version number received, if it needs to receive an update or not, instead of the remote server deciding if the script has to update or not. No particular reason beside I find that simpler, on first sight.

Hope this helps,
Tom :)
Post Reply