php中的会话不加载配置文件、php+;mysql
我需要能够定位与mysql数据库中的数据通信的php代码,该文件称为“validate.php”。它的主要功能是验证登录时没有空字段,如果用户的值为1,则分配一个配置文件;如果表“users”的记录中的值为0,则分配另一个配置文件 其思想是“validate.php”检查用户并根据他们的配置文件将其引导到页面,但我不能这样做 我的代码是:php中的会话不加载配置文件、php+;mysql,php,mysql,session,mysqli,profile,Php,Mysql,Session,Mysqli,Profile,我需要能够定位与mysql数据库中的数据通信的php代码,该文件称为“validate.php”。它的主要功能是验证登录时没有空字段,如果用户的值为1,则分配一个配置文件;如果表“users”的记录中的值为0,则分配另一个配置文件 其思想是“validate.php”检查用户并根据他们的配置文件将其引导到页面,但我不能这样做 我的代码是: <?php require('access_db.php'); session_start(); if(isset($_POST['send']))
<?php
require('access_db.php');
session_start();
if(isset($_POST['send'])) { // We verify that the form data has been sent
//We verify that the user_name and the user_pass fields are not empty
if(empty($_POST['user_name']) || empty($_POST['user_pass'])) {
echo"
<script>
alert('Please enter your username and password correctly ');
location.replace('login.php');
</script>
";
}else {
//"Clean" the form fields of possible malicious code
$user_name = mysqli_real_escape_string($link,trim($_POST['user_name']));
$user_pass = mysqli_real_escape_string($link,trim($_POST['user_pass']));
// We verify that the data entered in the form match those of the DB
$query=mysqli_query($link,"select user_id,user_name,user_admin FROM users WHERE user_name='".$user_name."' and user_pass ='".$user_pass."'");
$row = mysqli_fetch_array($query);
$_SESSION['user_id'] = $row['user_id'];
$_SESSION['user_name'] = $row["user_name"];
$_SESSION['user_admin'] = $row["user_admin"];
if($_SESSION['user_admin']==1){
echo "dashboard.php";
}else{
echo "dashboard2.php";
}
{
}
}else{
header("Location: login.php");
}?>
当我在我的页面“login.php”中使用我的管理员用户登录时,您应该检查信息并根据您的配置文件转到页面,仅显示在浏览器“”和页面上的文本“dashboard”中,但是,如果我在浏览器中写“加载包含所有信息的页面”
我不知道我做错了什么。
有人能帮我,我会非常感激的,我已经做了好几天了。
谢谢。您需要重定向,而不是回显php文件的内容 而且还要检查{因为还有额外的
if($_SESSION['user_admin']==1){
header("Location: dashboard.php");
}else{
header("Location: dashboard2.php");
}
不要打印,请尝试以下操作:
if($_SESSION['user_admin']==1){
header('location:dashboard.php');
exit;
}else{
header('location:dashboard2.php');
exit;
}
感谢Magnus Eriksson的建议当您想要重定向它们时,为什么要在屏幕上打印。您的代码容易受到SQL注入的影响-使用准备好的语句,而不是直接将变量嵌入sql@programmingArrow,您好,我的想法不是打印信息,正如您所说,我想通过配置文件重定向到我的页面,th阿肯斯到马格纳斯Eriksson@MagnusEriksson,非常感谢你的建议!!!我正在学习编程,我会犯错误,但感谢社区,我会学到更多。@RamRaider,我是做这件事的新手,非常感谢,我会了解你提到的内容。谢谢!!别忘了在标题后添加
退出;
,以确保标题正确无误直接发送,解析后无任何内容。感谢您的帮助,修改并最终进入我的个人资料。
if($_SESSION['user_admin']==1){
header('location:dashboard.php');
exit;
}else{
header('location:dashboard2.php');
exit;
}