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

Pardon for a weird title, didn't know how to put it. Essentially, I can't write anything after my existing PHP code (it contains a class, a couple of functions and an echo of a function). I tried basic HTML, and more PHP, none of it works.

Remembering back to when I did Python, it seems that it's a loop that's still running, thus preventing anything else from working.

My code:

<?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 :(

The first echo of authCode(); works, however, the line below it doesn't, regardless of what I write there. Any idea as to what the issue is? Or if it's the aforementioned "loop", how do I escape it? Feel free to outline my stupidity.

Note, PHP isn't my specialty, I primarily use Java and/or C# (because they're more fun than PHP), and just decided to do something fun in PHP, therefore my knowledge of the language is relatively limited.

1个回答

Try running the following at the end of your script.

echo "Authentication code: " . authCode();
echo "MD5 Checksum: " . md5(authCode()); 

I believe you're just not appending the php to the echo statement correctly as ';' indicates an end of line in PHP.

Upon further looking it looks like your 2nd instance of authCode is missing the opening and closing parenthesis.

It might be better to return a string in your authCode() function and set the result set authCode() equal to a variable so that you're not calling the authCode() funciton twice. Ex:

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


var $authvar = authCode();
echo "Authentication code: " . authvar;
echo "MD5 Checksum: " . md5(authvar);
duano3557
duano3557 更新:修正了上述问题,出现了更多问题(数字连接而不是添加,并且在实际数字输出之前显示文本“身份验证代码:”,并且MD5哈希根本不会更改:/)
3 年多之前 回复
drztpx8735
drztpx8735 使用authvar产生错误500解析错误:语法错误,第39行/var/www/html/auth.php中的意外'var'(T_VAR)更新:修复了问题,文本仍然没有出现
3 年多之前 回复
doudanglang5826
doudanglang5826 更新:我摆脱了错误500,现在只显示没有“验证码:”的号码,下面的行仍然没有出现(参考上面的链接了解实时结果)
3 年多之前 回复
dongzhang0418
dongzhang0418 再看一下,看起来最后一行应该在authCode之后有(),因为它指的是authCode()函数。
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐