-1

好的,我在我的login.php页面上收到此解析错误。似乎代码没有考虑检查用户是否已经登录。我pagechecker.php在每个页面上都有一个文件调用,用于检查是否已登录,但它的所有显示都是每个页面顶部的 php 代码。

错误login.php是:

解析错误:语法错误,意外的 '(',在第 21 行的 C:\inetpub\wwwroot\OTLCoding\PHP\login.php 中需要标识符 (T_STRING) 或变量 (T_VARIABLE) 或 '{' 或 '$'

基础.php

    <?php
    session_start();

    $dbhost = "localhost";
    $dbname = "login";
    $dbuser = "root";
    $dbpass = "DirectedStudies2012";

$mysqli = new mysqli($dbhost,$dbuser,$dbpass,$dbname);


?>

登录.php

    <?php 
 include ("base.php");
 include ("passwordchecker.php");
 include ("functions.php");
include("pagechecker.php");


    function postInput($htmlName)
    {
    if(isset($_POST[$htmlName]))
    {
    return $_POST[$htmlName];
    }
    return null;
    }

    //check if the user is already login.
            if(isset($_SESSION['userid']))
            {
                //check the database for existing user.
                $usercheck->$mysqli->("SELECT * FROM user WHERE userid = ?");
                $usercheck->bind_param("i",$_SESSION['userid']);
                $usercheck->execute();
                $usercheck->store_result();
                $results = $usercheck->num_rows;
                if($results == 1)
                {
                    redirect("languages.php");
                }
            }

    $loginusername = postInput('username');
    $loginpassword = postInput('password');



    if(isset($_POST['submit']))
    {

        if($loginusername == "" || $loginpassword == "")
        {
            $error = "Please Enter your user name and password";

        }
        else
        {
                //user isnt logged in
                if($stmt = $mysqli->prepare("SELECT userid, password FROM user WHERE username = ? LIMIT 1"))
                {
                    $stmt->bind_param("s",$loginusername);
                    $stmt->execute();
                    $stmt->bind_result($userid,$correctHash);
                    $stmt->fetch();
                    if(ValidatePassword($loginpassword,$correctHash))
                    {
                        $_SESSION['userid'] = $userid;
                        redirect('languages.php')
                    }
                    $stmt->close();
                }
            }
        }
    }



?>

页面检查器.php

//used to check for already login.
    if(!isset($_SESSION['userid']))
    {
        header("Location: login.php");
    }
    else
    {
        $usercheck->$mysqli->("SELECT * FROM user WHERE userid = ?")
        $usercheck->bind_param("i",$_SESSION['userid']);
        $usercheck->execute();
        $usercheck->store_result();
        $results = $usercheck->num_rows;
        if($results == 0)
        {
          header("Location: login.php");
        }
    }
4

3 回答 3

2

问题出在此处:

...->$mysqli->(...

你应该这样称呼它:

...->$mysqli(...

或者像这样:

...->mysqli(...

取决于是否$mysqli设置。

解释很简单。您可以调用类似的东西(在文档中查看更多信息):

$my_object->$my_variable_property_name('some argument');

但是调用属性名称和括号之间的箭头实际上是语法错误。

于 2012-05-20T05:34:37.173 回答
1

这里缺少分号:

$_SESSION['userid'] = $userid;
redirect('languages.php')
于 2012-05-20T05:29:24.720 回答
0
   $usercheck->$mysqli->("SELECT * FROM user WHERE userid = ?");
               ^----

这应该是

   $usercheck->mysqli->etc....
于 2012-05-20T05:25:05.013 回答