Page 1 of 1
Need help creating ver. indicator
Posted: Mon Dec 01, 2003 3:53 pm
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.
Posted: Mon Dec 01, 2003 5:05 pm
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.
Posted: Mon Dec 01, 2003 7:00 pm
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?
Posted: Mon Dec 01, 2003 8:21 pm
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.