duandingyou3331 2017-03-11 01:39
浏览 51
已采纳

如何在现有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条回答 默认 最新

  • dongyuli4538 2017-03-11 01:45
    关注

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化