1

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?

8
  • Firstly var_dump($script); to see if the output is string(5) "2.0.1" (string with 5 characters). Your txt file can have BOM in the beginning of the file or just space / new line at the end. Commented Aug 25, 2013 at 20:00
  • sorry i do know about php and whatnots just not good at it...and i dont understand what your saying there do i need to add var_dump($script); & string(5) "2.0.1" if so were at? Commented Aug 25, 2013 at 21:17
  • @Marlboroman213, Put var_dump($script); after $script = file_get_contents(REMOTE_VERSION); and tell us what you get? Commented Aug 25, 2013 at 23:38
  • @Starx that makes it say " bool(false) There is a update available!" even when changing the version number remotely Commented Aug 26, 2013 at 2:13
  • @Marlboroman213, this means that it is not readying the file properly. Make sure the file is readable. Commented Aug 26, 2013 at 2:50

2 Answers 2

1

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>";
}?>
Sign up to request clarification or add additional context in comments.

3 Comments

i tried ytour way with the same results everythihg is set correctly but its not working
there is no error it just wont say "You have the latest version!" if both the versions in the above script and the .txt file on remote server are same no matter what i do... it keeps saying "There is a update available!"
@Marlboroman213 check out the difference here
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.