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 有偿求码,CNN+LSTM实现单通道脑电信号EEG的睡眠分期评估
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体