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

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站