Php 成功登录后如何显示欢迎页面?
我在Model和View两个不同的文件夹中使用以下代码。视图中的文件夹包含两个php文件,如Login.php和Login_success.php。控制器文件夹包含mysql数据库表字段获取代码。当我运行下面的代码时,它无法显示登录成功页面。仅显示else字段检查名称和密码。所有这些文件都合并到文件夹外index.php 这是我的代码: Login.phpPhp 成功登录后如何显示欢迎页面?,php,javascript,mysql,Php,Javascript,Mysql,我在Model和View两个不同的文件夹中使用以下代码。视图中的文件夹包含两个php文件,如Login.php和Login_success.php。控制器文件夹包含mysql数据库表字段获取代码。当我运行下面的代码时,它无法显示登录成功页面。仅显示else字段检查名称和密码。所有这些文件都合并到文件夹外index.php 这是我的代码: Login.php <html> <head> <title>Login</title> <link re
<html>
<head>
<title>Login</title>
<link rel ='stylesheet' type = 'text/css' href = 'View/Design.css'>
<script>
function Validate(){
var x=document.forms["login"]["username"].value;
if (x==null || x=="")
{
alert("First name must be filled out");
return false;
}
var x=document.forms["login"]["password"].value;
if (x==null || x=="")
{
alert("Password must be filled out");
return false;
}
}
</script>
</head>
<body>
<form name = 'login' method = 'post' action = 'Controller/Controll.php' >
<fieldset>
<legend>Login</legend>
User Name :<input type = 'text' name = 'username'>
Password :<input type = 'password' name = 'password'><br><br>
<input type = 'submit' name = 'submit' value = 'submit' onsubmit = "return Validate()" >
</fieldset>
</form>
</body>
</html>
class Access{
function connection(){
require_once('View/Login.php');
$con = mysql_connect('localhost','root','root');
$db = mysql_select_db('Times_sheet');
$query = mysql_query('select * from Login');
$row = mysql_fetch_array($query);
if(isset($_POST['submit']))
{
if(($row['UserName']==$_POST['username']) && ($row['Password']==$_POST['password'])){
require_once("View/Login_Success.php");
}
}
else{
echo "Check User name and Password";
}
}
}
require_once('Controller/Controll.php');
class login extends Access{
function getValu(){
require_once('View/Login.php');
}
}
$Obj = new login();
$Obj ->getValu();
$Obj ->connection();
Index.php
<html>
<head>
<title>Login</title>
<link rel ='stylesheet' type = 'text/css' href = 'View/Design.css'>
<script>
function Validate(){
var x=document.forms["login"]["username"].value;
if (x==null || x=="")
{
alert("First name must be filled out");
return false;
}
var x=document.forms["login"]["password"].value;
if (x==null || x=="")
{
alert("Password must be filled out");
return false;
}
}
</script>
</head>
<body>
<form name = 'login' method = 'post' action = 'Controller/Controll.php' >
<fieldset>
<legend>Login</legend>
User Name :<input type = 'text' name = 'username'>
Password :<input type = 'password' name = 'password'><br><br>
<input type = 'submit' name = 'submit' value = 'submit' onsubmit = "return Validate()" >
</fieldset>
</form>
</body>
</html>
class Access{
function connection(){
require_once('View/Login.php');
$con = mysql_connect('localhost','root','root');
$db = mysql_select_db('Times_sheet');
$query = mysql_query('select * from Login');
$row = mysql_fetch_array($query);
if(isset($_POST['submit']))
{
if(($row['UserName']==$_POST['username']) && ($row['Password']==$_POST['password'])){
require_once("View/Login_Success.php");
}
}
else{
echo "Check User name and Password";
}
}
}
require_once('Controller/Controll.php');
class login extends Access{
function getValu(){
require_once('View/Login.php');
}
}
$Obj = new login();
$Obj ->getValu();
$Obj ->connection();
当我输入正确的用户名和密码时,它将进入空白页面。我不知道我犯了什么错误。你只是在这行中加入了
Login\u success.php
,而没有重定向到Login\u success.php
if(($row['UserName']==$_POST['username']) && ($row['Password']==$_POST['password'])){
require_once("View/Login_Success.php");
}
因此,使用标题
进行此重定向
if(($row['UserName']==$_POST['username']) && ($row['Password']==$_POST['password'])){
header("Location: View/Login_Success.php");
exit();
}
在查询中,您将从表“Login”中获取所有(*)结果 使用“WHERE”替换此查询表: 例如,从登录名中选择*,其中user=$\u POST['username']和password=$\u POST['password'] 如果找到结果,则将用户重定向到所需页面:
header("Location : View/Login_Success.php");
使用header php函数进行重定向,而不是一次请求_。像这样的格式头(url) 您必须更改代码
$query = mysql_query('select * from Login');
$row = mysql_fetch_array($query);
session_start();
$_SESSION['user'] = $row['UserName'] ;
要在Login\u Success.php中使用它,您可以使用以下代码:
<?php
session_start();
echo "wellcome user : ".$_SESSION['user'] ;
?>
我有两个报价给你:
1.在代码中使用反SQL注入。
2.使用headerheader('location:View/Login_Success.php')代码>对于重定向到其他页面不包括首先,您的代码根本不保存;和平是黑客的蛋糕
class Access{
function connection(){
require_once('View/Login.php');
$con = mysql_connect('localhost','root','root');
$db = mysql_select_db('Times_sheet');
$query = mysql_query('select * from Login');
$row = mysql_fetch_array($query);
if(isset($_POST['submit']))
{
第二,你只包括
View/Login_Success.php'
你必须这样做:
if(($row['UserName']==$_POST['username']) && ($row['Password']==$_POST['password'])){
header('location: View/Login_Success.php');
}
}
else{
echo "Check User name and Password";
}
}
}
我可以很容易地攻击你的系统,只要我在浏览器中禁用JavaScript。。。不要依赖客户端验证!!是的,我检查了它,但是Login_success.php页面没有打开,因为代码if(isset($\u POST['submit'])没有运行。它直接执行else部分。当我根据您的指导原则尝试时,最终我得到了错误,如“未定义索引:用户名,未定义索引:密码,mysql\u fetch\u array()期望参数1是资源,布尔给定”我正在编辑您的代码信息的答案,现在修复并测试它。是的,当我输入用户名和密码时,我会检查它是否显示空页面。如果(mysql_num_rows($query)==1){//logined}条件块无法执行。仍然是相同的问题。我认为你的php不是很好,请查看本页的教程如何创建登录页,但服务器没有检查条件,如果($row['UserName']=$\u POST['UserName'])&&($row['Password']=$\u POST['Password'])。它直接转到其他部分。