我在PHP中制作了一个反leech脚本的教程: http://tanksoftware.com/tutes/leechprotection.html
现在通过在线测试php文件,我变成了这个错误信息:
解析错误:语法错误,第14行/www/htdocs/myfolder/download.php中的意外T_VARIABLE 那条线有什么问题?
这是代码:
function generateSymLink($directory, $offset = 0) {
$day = "";
//todays day of the month, eg "14"
$day = date("d", time() + (24*3600*$offset));
// A string which would look somthing like this "Monday, 14 Jan 2003MySecretKey/myfiles/example"
$tohash = date("D, d M Y", time() + (24*3600*$offset))."My Secret Key".$directory
// The first seven digits of the hash of the above string which would look somthing like
// "a4h1b".
$smallkey = substr(md5($tohash),0,5);
return $day.$smallkey;
}
// extracts the file details
$fullpath = "myfiles/example/file.tar.gz";
$seperated = explode("/", $row['Filename']);
$actualfile = $seperated[sizeof($seperated)-1];
$path = substr($fullpath, 0,(strlen($fullpath)-strlen($actualfile)));
// Gets the current working directory
$wd = getcwd();
// Enters the download directory
chdir("dl") or die("Unable to enter the download directory");
// Creates a new symlink if nessesary
if (!file_exists(getSymLink($path)))
symlink("../".$path, getSymLink($path)) or die("Unable to create download link");
// changes back to the directory of the script
chdir ($wd);
// Returns the current day of the month
function getDnum($offset = 0) {
return date("d", time() + (24*3600*$offset));
}
// removes old symbolic links
function cleanUpOldSymlinks () {
// Only execute this code 1/10th of the time (to conserve CPU time).
$randomNumber = rand(0,10);
if ($randomNumber != 6)
return;
// enters the download directory
$wd = getcwd();
chdir("dl") or die ("Unable to enter directory dl");
// Deletes all symlinks that are not current
// As a symlink is only current for a maximum of 48 hours - and due to the
// hashing they are never repeated - this should effectivly prevent leeching.
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
// extracts the date of the symlink
$dateOfLink = substr($file,0,2);
// checks to see if it's current
if (($dateOfLink != getDnum(0)) && ($dateOfLink != getDnum(-1)) && strlen($file) > 2) {
// Removes the symlink
unlink($file);
}
}
}
closedir($handle);
}
chdir ($wd);
}
function getDownloadKey($file, $offset) {
return generateSymLink($file, $offset);
}
$file = getFilepathFromID($_GET['fileid']);
$key = $_GET['key'];
if ($key != getDownloadKey($file, 0) && $key != getDownloadKey($file, -1))
die ("invalid download key");
// else - download the file
// ...
?>
这篇教程对我的英语技能和PHP表现来说过于复杂,但我需要这样一个“反水蛭脚本”来保护我的下载。 所以任何提示和帮助都是非常受欢迎的。
感谢。
答案 0 :(得分:3)
你最后忘记了一个分号。
$tohash = date("D, d M Y", time() + (24*3600*$offset))."My Secret Key".$directory;