RobsPalace
RobsPalace

Reputation: 15

version update script for a script

I'm going to try making this easy to understand and hope it makes sense.

I have a PHP script / template and I want the end user to be able to know when I updated something, (eg. template change or a bugfix) and they can click a link to download the updated version from a remote host. I tried the scripts posted on PHP - How to check a script version and I sorta got this script working:

<?php define('REMOTE_VERSION', http://mysite.com/_client/client_name/update/version_check.txt');
    define('VERSION', '2.0.1');
    $script = file_get_contents(REMOTE_VERSION);
    $version = VERSION;
    if($version == $script) {
        echo "<div class=success> 
    <p>You have the latest version!</p> 
    </div>";
    } else {
        echo "<div class=error> 
    <p>There is a update available!</p> 
    </div>";
    }?>

Well sort of... The .txt file on my remote server just has 2.0.1. Since they are the same version (both 2.0.1), it should read "You have the latest version!" In this case it says "There is a update available!" no matter what number I put in.

define('VERSION', '2.0.1'); //in php above 

2.0.5 //in .txt file on remote server

Says same things as it should because on the remote server is showing a new update (eg. 2.0.5). Can anyone tell me what I am doing wrong?

Upvotes: 1

Views: 211

Answers (2)

Intact Dev
Intact Dev

Reputation: 506

You forgot to put a quote on the second part of the define('REMOTE_VERSION', ...); line. I added in the quote, and you also added unnecessary lines of code by reassigning the defined variable VERSION to a new variable $variable. This script should work; I've used something similar to this before.

<?php 
define('VERSION', '2.0.1');
$script = file_get_contents('http://mysite.com/_client/client_name/update/version_check.txt');
define('REMOTE_VERSION', $script);
if(VERSION == REMOTE_VERSION) {
    echo "<div class='success'> 
<p>You have the latest version!</p> 
</div>";
} else {
    echo "<div class='error'> 
<p>There is a update available!</p> 
</div>";
}?>

Upvotes: 1

Starx
Starx

Reputation: 78971

This might be a typo, but there is an error at your constant definition.

define('REMOTE_VERSION', http://mysite.com/_client/client_name/update/version_check.txt');
                     // ^ Missing quote

Upvotes: 0

Related Questions