簡體   English   中英

PHP 腳本版本檢查/通知

[英]PHP Script Version Checking/Notification

如何根據在線文件檢查我的腳本版本以查看它是否是最新版本?

為了澄清起見,我說的是我編寫的腳本,而不是 PHP 的版本。 我想加入一種讓最終用戶知道我何時更新腳本的方法。

要指定第二個(更簡單)解決方案phjr

在您自己的公共服務器上有一個文件version.txt ,並在您部署的項目/腳本中包含以下函數:

define('REMOTE_VERSION', 'http://your.public.server/version.txt');

// this is the version of the deployed script
define('VERSION', '1.0.1');

function isUpToDate()
{
    $remoteVersion=trim(file_get_contents(REMOTE_VERSION));
    return version_compare(VERSION, $remoteVersion, 'ge');
}

version.txt應該只包含最新的版本號,例如:

1.0.2

根據這個答案的評論

// Substitue path to script with the version information in place of __FILE__ if necessary
$script = file_get_contents(__FILE__);
$version = SOME_SENSIBLE_DEFAULT_IN_CASE_OF_FAILURE;
if(preg_match('/<!-- Script version (\d*(\.\d+)*) -->/', $script, $version_match)) {
    $version = $version_match[1];
}
define('REMOTE_VERSION', 'http://your.public.server/version.txt');
define('VERSION', '1.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>";
}

有更新信息的RSS或Atom 飼料 Wordpress做了類似的事情。 然后,您可以在本地保存已向用戶顯示更新的信息等。

對於更簡單的解決方案,在項目網站上有一個僅包含版本號的文件。 然后將其與存儲在程序中的版本號進行比較,可能在常量內。

if($version == $script) 到 if($version >= $script)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM