Version Check Function

Discussion in 'PHP' started by Rory M, Aug 10, 2008.

  1. #1
    Hi :)

    I am looking for the best way to get my script to "call home" and check for the current available version & if necessary tell the user that they need to update.

    I can do the rest if some clever person could point me in the direction of getting the variable from my server in some way.

    Thanks
    Rory
     
    Rory M, Aug 10, 2008 IP
  2. Jasber

    Jasber Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Have a file on your server that contains the version number.

    $version = file_get_contents("http://www.website.com/version.txt");

    Then check if $version is newer than the current version.

    You could store each version with the same name, so you automatically have the filename you need to download.

    Then to update to a new version simply update version.txt.

    Make the client check on a cron job or everytime the script opens.
     
    Jasber, Aug 10, 2008 IP
  3. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #3
    cURL and AJAX could be options but cURlL library may not always be installed and with JavaScript, there can be some cross-domain issues(I think). fopen() and file_get_contents() may be restricted and not allowed to open remote files!

    So what I suggest is that you include a small JavaScript on the client's system that gets its content from your server.

    1.JavaScript on your clients server
    Look at the client's version that I have appended to the 'src' attribute
    
    <script type="text/javascript" src="remote_file_on_ur_server.php?client_version=1.5.15"></script>
    
    Code (javascript):
    2. Remote file on your server "remote_file_on_ur_server.php"
    
    <?php
    $client_version=$_GET['client_version'];
    $latest_version='1.5.20';//edit this value when a new version is available
    if($client_version!=$latest_version)
    {
    echo 'alert(\'Dear Client, Please upgrade\')';
    // or echo the javascript that you need
    }
    ?>
    
    PHP:
     
    rohan_shenoy, Aug 10, 2008 IP
  4. Rory M

    Rory M Peon

    Messages:
    1,020
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Okay, that looks good to me.

    Is it only echo I can use within the 'if' body? Or could I call a function in the local script with it somehow? How would $_SESSION variables work with this scenario, sounds difficult just asking about it :s
     
    Rory M, Aug 10, 2008 IP
  5. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #5
    I doubt if you can call functions or other variables on your client's server because you don't have any access to their server memory.
     
    rohan_shenoy, Aug 10, 2008 IP
  6. Rory M

    Rory M Peon

    Messages:
    1,020
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Okay then, I can probably work with what you gave me - thanks a lot :) Just one more thing, all of that would work with SSL encryption, correct?
     
    Rory M, Aug 10, 2008 IP
  7. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #7
    It should but I have no idea as I have hardly dealt with SSL.
     
    rohan_shenoy, Aug 10, 2008 IP
    Rory M likes this.
  8. Rory M

    Rory M Peon

    Messages:
    1,020
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Allright, thanks once again (+REP for all your help)
     
    Rory M, Aug 10, 2008 IP