开发者

PHP: unexpected T_VARIABLE error [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. 开发者_运维百科 Closed 9 years ago.

I made this tutorial for an anti leech script in PHP: http://tanksoftware.com/tutes/leechprotection.html

Now by testing the php file online I become this error message:

Parse error: syntax error, unexpected T_VARIABLE in /www/htdocs/myfolder/download.php on line 14 What is wrong on that line?

This is the code:

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
    // ...

    ?>

The tutorial is way too complex for my english skills and PHP expierence but I need such an "anti leech script" to protect my downloads. So any tips and help is very welcome.

Thanks.


You forgot a semicolon at the end.

$tohash = date("D, d M Y", time() + (24*3600*$offset))."My Secret Key".$directory;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜