我搜索了网站并看到了用户应该在变量周围放置单引号的问题的修复程序,但我仍然有些困惑。
错误:(全部参考第28行) 注意:使用未定义的常量log_id - 假设为'log_id' 注意:使用未定义的常量log_username - 假定为'log_username' 注意:使用未定义的常量log_password - 假定为'log_password'
脚本:
<?php
session_start();
include ("includes/connection.php");
$user_ok = false;
$log_id = "";
$log_username = "";
$log_password ="";
function evalLoggedUser($con,$id,$u,$p){
$sql = "SELECT ip FROM users WHERE id='$id' AND username='$u' AND password='$p' AND activated='1' LIMIT 1";
$query = mysqli_query($con, $sql);
$numrows = mysqli_num_rows($query);
if($numrows > 0){
return true;
}
}
if(isset($_SESSION["userid"]) && isset($_SESSION["username"]) && isset($_SESSION["password"])) {
$log_id = preg_replace('#[^0-9]#', '',$_SESSION['userid']);
$log_username = preg_replace('#[^a-z0-9]#i','', $_SESSION ['username']);
$log_password = preg_replace('#[^a-z0-9]#i','', $_SESSION ['password']);
//VERIFY USER
$user_ok = evalLoggedUser($con,log_id,log_username,log_password);
} else if(isset($_COOKIE["id"]) && isset($_COOKIE["user"]) && isset($_COOKIE["pass"])) {
$_SESSION['userid'] = preg_replace('#[^0-9]#', '',$_COOKIE['userid']);
$_SESSION ['username'] =preg_replace('#[^a-z0-9]#i','', $_COOKIE ['username']);
$_SESSION['password'] = preg_replace('#[^a-z0-9]#i','', $_COOKIE ['username']);
//CREATE LOCAL SHORT VARIABLES
$log_id = $_SESSION['userid'];
$log_username = $_SESSION['username'];
$log_password = $_SESSION['password'];
if($user_ok == true){}
//UPDATE LAST LOGIN TIME
$sql = "UPDATE users SET lastlogin=now() WHERE id='$log_id' LIMIT 1";
$query = mysqli_query($con,$sql);
}
?>
答案 0 :(得分:1)
更改此行,您忘记了变量前面的$:
$user_ok = evalLoggedUser($con,$log_id,$log_username,$log_password);
答案 1 :(得分:0)
你忘了放美元符号。
替换它:
$user_ok = evalLoggedUser($con,log_id,log_username,log_password);
用这个:
$user_ok = evalLoggedUser($con,$log_id,$log_username,$log_password);
答案 2 :(得分:0)
$user_ok = evalLoggedUser($con,log_id,log_username,log_password);
更改为:
$user_ok = evalLoggedUser($con,$log_id,$log_username,$log_password);