好的,我在我的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");
}
}