我想实现一个简单的脚本,当桌面应用程序调用时,托管在web服务器中,递增存储在简单文本文件或简单数据库中的值。我想用密码保护计数器,这样只有我的应用程序才能激活脚本并递增value.Please帮助我该如何做我已经得到了计数器的基本代码
<?php
2 $counter = ("hitcounter.txt");
3 $hits = file($counter);
4 $hits[0]++;
5 $fp = fopen($counter , "w");
6 fputs($fp , "$hits[0]");
7 fclose($fp);
8 // echo $hits[0];
9 ?>发布于 2012-03-21 20:30:35
您可以使用基本的HTTP authentication on php。
来自php.net的示例
<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Text to send if user hits Cancel button';
exit;
} else {
// check $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW']}
// and increase your counter here
}
?>https://stackoverflow.com/questions/9804541
复制相似问题