doufei8691 2012-10-30 18:29 采纳率: 100%
浏览 4
已采纳

使用OO-PHP进行简单登录[关闭]

I'm trying just to validate, on submitting the form that the username and password aren't empty.

Form:

<form action="usercheck.php" method="post">
    User: <input type="text" name="username" maxlength="10" />
    Pass: <input type="password" name="password" maxlength="10" />      
    <input type="submit" value="Submit" />
</form>

usercheck.php

<?php

class Vuln{

    public $username = $_POST['username'];
    public $password = $_POST['password'];

    public function ShowErrors(){
        if($this->username == '' || $this->password == ''){
            return 'username or password field blank';  
        }
        else{
            echo stripslashes('we\'re good');
        }   
    }

    $entered = new Vuln;
    echo $entered->ShowErrors();

}


?>

When I test, it says:

Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION on line :

    $entered = new Vuln;
  • 写回答

6条回答 默认 最新

  • dongyi0210 2012-10-30 18:31
    关注

    You can't have code inside a class definition like that

        class Vuln {
           //> Your class definition
        }
    
        //> Outside of the class
    
        $entered = new Vuln;
        echo $entered->ShowErrors();
    

    I strongly suggest you to read all the basics from PHP Doc

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序