code_junkie

PHP Script Version Checking/Notification

Nov 11th, 2011
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. define('REMOTE_VERSION', 'http://your.public.server/version.txt');
  2.  
  3. // this is the version of the deployed script
  4. define('VERSION', '1.0.1');
  5.  
  6. function isUpToDate()
  7. {
  8. $remoteVersion=trim(file_get_contents(REMOTE_VERSION));
  9. return version_compare(VERSION, $remoteVersion, 'ge');
  10. }
  11.  
  12. 1.0.2
  13.  
  14. // Substitue path to script with the version information in place of __FILE__ if necessary
  15. $script = file_get_contents(__FILE__);
  16. $version = SOME_SENSIBLE_DEFAULT_IN_CASE_OF_FAILURE;
  17. if(preg_match('/<!-- Script version (d*(.d+)*) -->/', $script, $version_match)) {
  18. $version = $version_match[1];
  19. }
  20.  
  21. define('REMOTE_VERSION', 'http://your.public.server/version.txt');
  22. define('VERSION', '1.0.1');
  23. $script = file_get_contents(REMOTE_VERSION);
  24. $version = VERSION;
  25. if($version == $script) {
  26. echo "<div class=success>
  27. <p>You have the latest version!</p>
  28. </div>";
  29. } else {
  30. echo "<div class=error>
  31. <p>There is a update available!</p>
  32. </div>";
  33. }
Add Comment
Please, Sign In to add comment