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

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

User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Ah. Clever.

What they're doing is just displaying an image from their server. For example, imagine you have an HTML page with an image in it called "http://www.domain.com/upgrade.jpg" ... that just displays the image from domain.com. Using PHP you can dynamically generate an image (with GD). So if you set php properly you can call something like upgrade.jpg?version=123, and build an image based on that. Obviously you'd make a "you need to upgrade" image if the latest version was lower than the version passed in the GET request.

Essentially it completely bypasses PHP. It's just done in the browser. That's a very sensible approach really because it doesn't rely on URL wrappers or external calls of any sort being available on the server.
tarja311
Forum Commoner
Posts: 73
Joined: Fri Oct 20, 2006 10:57 pm

Post by tarja311 »

Thanks for that bit of info.

I have looked up GD and used the following code:

Code: Select all

<?php
function LoadPNG($imgname)
{
   $im = @imagecreatefrompng($imgname); /* Attempt to open */
   if (!$im) { /* See if it failed */
       $im  = imagecreatetruecolor(150, 30); /* Create a blank image */
       $bgc = imagecolorallocate($im, 255, 255, 255);
       $tc  = imagecolorallocate($im, 0, 0, 0);
       imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
       /* Output an errmsg */
       imagestring($im, 1, 5, 5, "Error loading $imgname", $tc);
   }
   return $im;
}
header("Content-Type: image/png");
$img = LoadPNG("http://mydomain.com/upgrade.png");
imagepng($img);
?>
Unfortunately this requires that i have the fopen wrappers on also. All i receive is a timeout for about 3-5 minutes then the "Error loading" message. It only works if i call for the image locally. Anyways, is this what you meant in the post above?
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

try a normal image tag..

<img src="http://mydomain.com/upgrade.png">
tarja311
Forum Commoner
Posts: 73
Joined: Fri Oct 20, 2006 10:57 pm

Post by tarja311 »

Using just the image tag works fine, but the situation has to be conditional. If my apps version is this, show this image, if my apps version is that, show that image.

Without the fopen wrapper i am totally stumped here. :cry:
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Without url fopen, you will be forced to display the image, and if the version is out of date, insert into the image that it needs upgrading, and if it's not, don't insert anything.
tarja311
Forum Commoner
Posts: 73
Joined: Fri Oct 20, 2006 10:57 pm

Post by tarja311 »

Ok but how does the app know it is out of date if it can't connect to the remote server to check against version number?

I'm sorry to sound so newbie-ish.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

That's just it.. the app won't. The only way that I can see the app being able to determine whether or not it is current is to have url fopen turned on.

The best you will be able to do is to display a message that it should be upgraded.
Post Reply