在脚本中使用未定义的常量 [英] Use Of Undefined Constant in script

查看:73
本文介绍了在脚本中使用未定义的常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了该站点,并看到针对该问题的修复程序,在该问题中,用户应该在变量周围加上单引号,但是我仍然有些困惑.

I've searched the site and saw fixes for the issue in which the user should have put single quotes around the variable but I still a bit confused.

错误:(均参考第28行) 注意:使用未定义的常数log_id-假定为'log_id' 注意:使用未定义的常数log_username-假定为'log_username' 注意:使用未定义的常数log_password-假定为'log_password'

Errors: (all refer to line 28) Notice: Use of undefined constant log_id - assumed 'log_id' Notice: Use of undefined constant log_username - assumed 'log_username' Notice: Use of undefined constant log_password - assumed '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);
}


?>

推荐答案

更改此行,您忘记了变量的$ infront:

Change this line, you forgot the $ infront of the variables:

$user_ok = evalLoggedUser($con,$log_id,$log_username,$log_password);

这篇关于在脚本中使用未定义的常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆