Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果用户具有2级或更高级别的访问权限,则重定向_Php_Mysql - Fatal编程技术网

Php 如果用户具有2级或更高级别的访问权限,则重定向

Php 如果用户具有2级或更高级别的访问权限,则重定向,php,mysql,Php,Mysql,所以我正在做一个简单的PHP项目,我对PHP没有太多的经验 也许你们可以帮我 我有一个存储用户凭据的数据库,如下所示 id|Username|Password| Mail |Acces| 1 |Josh | ***** |Something@hotmail.com| 1 | 2 |Rick | **0** |Generalpo@hotmail.com| 2 | 在我的php页面上,我想这样做,如果数据库的访问级别高于1,它将执行重定向。我是

所以我正在做一个简单的PHP项目,我对PHP没有太多的经验

也许你们可以帮我

我有一个存储用户凭据的数据库,如下所示

id|Username|Password|          Mail       |Acces|
1 |Josh    | *****  |Something@hotmail.com|  1  |
2 |Rick    | **0**  |Generalpo@hotmail.com|  2  |
在我的php页面上,我想这样做,如果数据库的访问级别高于1,它将执行重定向。我是用echo的权利来做的,所以我不会一直被重定向。但每次我这样做,我只是觉得我没有足够的权利。当我使用用户名Josh登录时

$sql = "SELECT * From login Where Username= "'$_SESSION('username')'"";
while($row = mysql_fetch_row($sql));
if ($row['Acces'] == "1"){
Echo("You have enough rights");
}else{
Echo("You dont have enough rights");
};
谢谢你的帮助

$sql = "SELECT * From login Where Username= "'$_SESSION('username')'"";
while($row = mysql_fetch_row($sql));
if ($row['Acces'] == "1"){
header('Location: http://www.example.com/'); /* Redirect browser */
}else{
echo('You dont have enough rights');
};

更改为您想要的。

您部分正确,但我会做一些更改:

$sql = mysql_query("SELECT * FROM login WHERE Username= '".mysql_real_escape_string($_SESSION['username'])."'");
$sql_fetched = mysql_fetch_assoc($sql);

if ($sql_fetched['Acces'] > 1)
{
    echo "You have enough rights and will be redirected automatically.";
    header('refresh:3;url=redirect.php');
}
else
{
    echo "You dont have enough rights.";
    header('refresh:3;url=login.php');
}

带有
位置的头需要一个绝对URI,而不仅仅是
某个地方。php
首先,您要使用
来压缩字符串
是PHP中正确的运算符。其次,您正在使用
访问
$\u会话
数组,尽管在PHP中访问数组的方法是通过括号
[
]
。我知道这是从OP贴出来的,但你应该纠正它。哦,太困了。对不起<代码>标题('位置:http://www.example.com/'); /* 重定向浏览器*/
@S.Visser是的-丹麦现在还是早上,所以您必须原谅我的打字错误。:-)我希望这能准确地回答您的问题。SQL注入量仍在不健康地进行,除非
$\u SESSION
在您的系统中以某种方式成为一个函数,否则这将不起作用。是的,它起作用了,检查了两个帐户,并知道如何执行重定向,消息就会出现!非常感谢。。它们不再得到维护。看到了吗?相反,学习,并使用or-将帮助您决定哪一个。如果选择PDO,。则当前正在检查accesslevel是否等于“1”。您应该将其修改为>(高于)。
$sql = "SELECT * FROM `login` Where `Username`='{$_SESSION['username']}'";

while($row = mysql_fetch_row($sql)) {
    if ($row['Acces'] == "1") {
        // Change these two headers to the file you want to redirect too
        header("Location: http://www.yoursite.com/enoughrights.php");
    } else {
        header("Location: http://www.yoursite.com/notenough.php");
    }
}