无法登录-且没有错误消息.-PHP [英] Unable to login - and no error message. - PHP
问题描述
<?php
include("includes/connect.php");
if(isset($_POST['login'])){
$user_name = $_POST['user_name'];
$user_pass = $_POST['user_pass'];
$admin_query = "select * from admin_login where user_name='$user_name' AND user_pass='$user_pass'";
$run=mysql_query($admin_query);
if(mysql_num_rows($run)>0){
//echo (mysql_num_rows($run));
$_SESSION['user_name']=$user_name;
header('location:index.php');
//echo "<script>window.open('index.php','_self')</script>";
}
else{
echo "<script>alert('User name or password is incorrect')</script>";
}
}
?>
我无法登录到索引页面.当我输入错误的凭证时,它会弹出错误.但是,当我提供正确的凭据时,它不会弹出任何错误.但仍然无法登录.请帮忙.
I am unable to login to the index page. When I give the wrong credential, it pops up the error. But when I give the right credentials, it doensn't pop any error. but still couldn't able to login. Please help.
我已将其包含在我的index.php中
I have included this on my index.php
<?php
session_start();
if(!isset($_SEESION['user_name'])){
header("location:login.php");
}
else {
?>
推荐答案
在代码顶部添加 session_start();
;这是因为除非会话开始并且您的 $ _ SESSION ['user_name'] = $ user_name;
当前不执行任何操作,否则您无法保存会话变量.
Add session_start();
at the top of your code; it's because you can't save a session variable unless the session is started and your $_SESSION['user_name']=$user_name;
doesn't do anything currently.
And your code is vulnerable to SQL injection attacks, read this question on how to prevent them.
这篇关于无法登录-且没有错误消息.-PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!