本文介绍了“在写上下文中不能使用函数返回值” PHP中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在哪种情况下会触发此类错误?
In which cases such errors get triggered?
我的程序:
My program:
//QUERY VARIABLE
$query="select * form user where user_name='$user_name' and user_password='sha($user_password)'";
//ESTABLISHING CONNECTION
$result=mysqli_query($dbc,$query)or die('Error Querying Database');
while($row=mysqli_num_rows($result)==1)
{
//SET COOKIE
setcookie('user_name',$row['user_name']);
setcookie('user_id',$row['id']);
$query="select * form user";
$result=mysqli_query($dbc,$query)or die('Error Querying Database');
$page_url='http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/index.php';
header('Location'.$page_url);
}
//TERMINATING CONNECTION
mysqli_close($dbc);
}
else
{
$error_msg='Please type both user name and password correctly to login';
}
//}
}
else
{
$page_url='http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/register.php';
header('Location'.$page_url);
}
}
if($output_form)
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Mismatch - Log In</title>
<link rel="stylesheet" href="stylesheets/style.css" media="all" />
</head>
<body class="body_style">
<?php
echo('<label class="signin_label">'.$error_msg.'</label>');
?>
<h2>Mismatch - Where Matches Happen...</h2>
<fieldset>
<legend>Mismatch - Log In</legend>
<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>"><!--Self Referencing Form-->
<label class="signin_label">USER NAME</label>
<input type="text" name="user_name" title="Enter Your Account User Name" class="signin_textbox" value="<?php if(!empty($_POST['user_name']))$_POST['user_name']; ?>" /><br />
<label class="signin_label">PASSWORD</label>
<input type="password" name="user_pwd" title="Enter Your Account Password" class="signin_textbox" value="" /><br />
</fieldset>
<input type="submit" name="login_submit" title="Click To Log In" value="Log In" class="button" />
<?php
}
?>
</body>
</html>
推荐答案
尝试更改
if(!isset($_COOKIE(user_id)))
至
if(!isset($_COOKIE['user_id']))
^^ ^^
是一个关联数组。
$_COOKIE
is an associative array.
这篇关于“在写上下文中不能使用函数返回值” PHP中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!