我在使用此代码初始化 在 header() code>时遇到了一些问题。 似乎
if code>语句不适用于查询变量? p>
init.php code>中函数
$ user_data code>已定义。
$ url code>是浏览器url-bar中的
$ _ GET code>代码(在本例中为6位随机代码)。 变量似乎有效,因为我已经尝试输出它们。 问题似乎是
if code>语句。 我没有收到错误消息。 即使我没有登录并且在MySQL中将url设置为
public === 0 code>,
header() code>也不会启动。 我哪里错了? p>
include'core / init.php';
include'include / head.php';
$ url = $ _SERVER ['QUERY_STRING' ];
$ url = sanitize($ url);
$ public_arr = mysql_query(“SELECT`public` FROM`uploads` WHERE`url` ='$ url'和`active` = 1”)或死 (mysql_error());
$ public_arr = mysql_fetch_assoc($ public_arr);
$ public = $ public_arr ['public'];
$ owner_arr = mysql_query(“SELECT` owner` FROM`uploads` WHERE` url` ='$ url'和`active` = 1“)或死(mysql_error());
$ owner_arr = mysql_fetch_assoc($ owner_arr);
$ owner = $ owner_arr ['owner'];
\ nglobal $ user_data;
if($ public === 0 AND $ owner!== $ user_data ['username'] || logged_in()=== false){
header('Location:mainpage.php');
exit();
}
$ name_arr = mysql_query(“SELECT`name` FROM`uploads` WHERE`url` ='$ url'和`active` = 1”)或死(mysql_error() );
$ name_arr = mysql_fetch_assoc($ name_arr);
$ name = $ name_arr ['name'];
code> pre>
div>
Assuming the variable values are as you say they are, try checking these vlaues are equal to and not identical, some times the types can vary (integers like 0
may be strings like "0"
).
if ($public == 0 AND $owner != $user_data['username'] || logged_in() === false) {
header('Location: mainpage.php');
exit();
}
As @jay-blanchard says, you should be using MySQLi functions instead of mysql_*
for many reasons - the main that they're not supported as standard in PHP any more!