使用未定义的常量控制台

时间:2014-12-30 17:37:56

标签: php

我收到此通知说:

Use of undefined constant console - assumed 'console'

当我尝试在控制台中打印变量的值时。

if(!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])){
    header('HTTP/1.1 401 Unauthorized');
    header('WWW-Authenticate: Basic realm="asr-web-dev1"');
    exit('<h3>Sorry!</h3><p>You must enter your username and password to log in and access this site.');
}

$db = new ezSQL_mysql(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
$username = trim($_SERVER['PHP_AUTH_USER']);
$password = trim($_SERVER['PHP_AUTH_PW']);
$count = $db->get_var("select count(*) as count from users WHERE user_name='" . $username . "' AND password='" . $password . "'");

if($count == 1){ 
    $data = $db->query("SELECT * FROM users WHERE user_name='" . $username . "' AND password='" . $password . "'");
    console.log($data);
    $user_id = $data['user_id'];
    $name = $data['name'];
} else {
    header('HTTP/1.1 401 Unauthorized');
    header('WWW-Authenticate: Basic realm="asr-web-dev1"');
    exit('<h3>Sorry!</h3><p>You must enter your username and password to log in and access this site.');
}

2 个答案:

答案 0 :(得分:4)

php中没有JS控制台对象

而不是console.log($data);使用echo $data;print_r($data);var_dump($data);

答案 1 :(得分:2)

或者,您可能只是在寻找PHP函数 error_log 来写入(惊喜)错误日志。以下是PHP手册的链接,说明了此功能的工作原理http://php.net/manual/en/function.error-log.php