Need help creating ver. indicator

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
TheNinthPlayer
Forum Newbie
Posts: 2
Joined: Mon Dec 01, 2003 3:53 pm

Need help creating ver. indicator

Post by TheNinthPlayer »

I am tring to create a version indicator for my php script. But I'm not sure how to do it. This is how I invision it happening.

The php script would go to a website and download a small XML file (http://www.com/ver.xml). It would then take the one line which would be something like "The current version is 1.22" and display it on the page.

Any one know what code I would need to do this? thx.
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Post by mrvanjohnson »

You can even make it easier than that.

Create a simple text file on a web server somewhere that contains the current version (i.e. The current version is 1.22)

Then in you application create a currentVersion function that simply uses the [php_man]file command[/php_man] and echo the result something like

Code: Select all

<?php
$version_array = file ('http://www.example.com/version.txt'); 
$version = implode ("", $version_array);
print $version;

?>
I think that would work, haven't tested it.

Then if you wanted to get fancy you could manipulate the array to check the version of the application the user is running and compare it to the current version and if there is a difference you can send it into another routine to help the user update.
TheNinthPlayer
Forum Newbie
Posts: 2
Joined: Mon Dec 01, 2003 3:53 pm

Post by TheNinthPlayer »

Thx. That worked but this brings a new problem that I probaly should have seen comming.

This script I write is sometimes used by people while offline (They have the nesscary php tools setup though). And if they are offline they cant access the file. As a result they would recieve the following statement

Code: Select all

Warning: file("http://www.com/ver.txt") - Success in /home/.bacci/run.inc on line 999

Warning: Bad arguments to implode() in /home/.bacci/run.inc on line 1000
Can I use some kind of IF statment to have the script say something like "Can't Access this file right now" instead of having the user recieve and error message?
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Comment on php.net in documentation of [php_man]file_exists[/php_man]
If you are trying to check whether a remote file (or url) exists, you can open it and close it in the same statement.

Code: Select all

<?php

if (@fclose(@fopen("http://www.example.com", "r"))) {
     print("File exists.");
} else {
     print("File does not exist.");
}

?>
The @ will means that the function will not report an error regardless whether it worked correctly or not.
Post Reply