如何在现有PHP脚本之后使附加代码工作?

如何在现有PHP脚本之后使附加代码工作?,php,html,Php,Html,请原谅一个奇怪的标题,我不知道怎么说。 本质上,我不能在现有PHP代码之后编写任何东西(它包含一个类、两个函数和一个函数的回音)。我尝试了基本的HTML和更多的PHP,但都不管用 回想我编写Python的时候,它似乎是一个仍在运行的循环,因此阻止了其他任何操作 我的代码: <?php //We're using a newer and older generation algorithms in order to create different results //The time a

请原谅一个奇怪的标题,我不知道怎么说。 本质上,我不能在现有PHP代码之后编写任何东西(它包含一个类、两个函数和一个函数的回音)。我尝试了基本的HTML和更多的PHP,但都不管用

回想我编写Python的时候,它似乎是一个仍在运行的循环,因此阻止了其他任何操作

我的代码:

<?php

//We're using a newer and older generation algorithms in order to create different results
//The time and date is used as a basic "salting" mechanism, which will make the number hard to determine without knowing the generation time
//I should consider using more secure generation, such as "random_int"
//EXTREMELY WIP!!!

class authGeneration
{

    private function gen($maxOne) {

        $begin_value_one = date("sih") * rand(1,100);
        $auth_value_one = mt_rand($begin_value_one, $maxOne);
        echo $auth_value_one;
    }

    private function genAdd($maxTwo) {

        $begin_value_two = date("his") + mt_rand(1000,1000000);
        $auth_value_two = rand($begin_value_two, $maxTwo);
        echo $auth_value_two;
    }

    public function finalGen() {

        $begin_value_three = date("dmY");
        $auth = $this->gen(999999999) + $this->genAdd(999999999); //No more than 999999999, no less than 100000000 (for both)
        $add = $auth + $begin_value_three;
        echo parseFloat ($add);
    }

}

function authCode() {
    $obj = new authGeneration();
    echo $obj->finalGen();
}

echo "Authentication code: "; authCode();
echo "MD5 Checksum: "; md5(authCode); //Doesn't work :(

尝试在脚本末尾运行以下命令

echo "Authentication code: " . authCode();
echo "MD5 Checksum: " . md5(authCode()); 
我相信您只是没有将php正确地附加到echo语句中作为“;”指示PHP中的行尾

进一步查看,您的第二个authCode实例似乎缺少开头和结尾括号

最好在authCode()函数中返回一个字符串,并将结果集authCode()设置为一个变量,这样就不会调用authCode()函数两次。例:

function authCode() {
    $obj = new authGeneration();
    return $obj->finalGen();
}


var $authvar = authCode();
echo "Authentication code: " . authvar;
echo "MD5 Checksum: " . md5(authvar);

再看一眼,看起来authCode后面的最后一行应该是()因为它引用的是authCode()函数更新:我去掉了错误500,现在它只显示数字而没有“Authentication code:”,下面的一行仍然没有出现(有关实时结果,请参阅上面的链接)使用
authvar
生成错误500
Parse Error:syntax Error,第39行/var/www/html/auth.php中意外的'var'(T_var)
更新:修复了问题,文本仍然没有出现更新:修复了上述问题,出现了更多问题(数字被连接而不是添加,文本“身份验证代码”:在实际数字输出之前显示,并且MD5哈希值根本不会更改:/)