Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.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_Php_Mysql_Redirect_Login - Fatal编程技术网

登录页面重定向php

登录页面重定向php,php,mysql,redirect,login,Php,Mysql,Redirect,Login,我的页面只有一页时工作正常。一旦我将重定向添加到另一个页面,则“记住我”复选框似乎不再起作用。我不确定退出命令是否会影响它,一旦我删除了else和exit,它就会记住。 我正在尝试创建一个管理员用户配置文件。 管理员=1 用户=0 我试图拆除出口;和重定向 但我真的想保留它们 <!DOCTYPE html> <head> <!-- Bootstrap core CSS --> <link href="bootstrap.min.css" r

我的页面只有一页时工作正常。一旦我将重定向添加到另一个页面,则“记住我”复选框似乎不再起作用。我不确定退出命令是否会影响它,一旦我删除了else和exit,它就会记住。 我正在尝试创建一个管理员用户配置文件。 管理员=1 用户=0

我试图拆除出口;和重定向

但我真的想保留它们

<!DOCTYPE html>

  <head>
<!-- Bootstrap core CSS -->
    <link href="bootstrap.min.css" rel="stylesheet">
  </head>

<style>
.alert {
    text-align: center;
    padding: 12px;
    background-color: #f44336; /* Red */
    color: white;
    margin-bottom: 10px;  
}
</style>


<?php
session_start(); // Starting Session
$error=''; // Variable To Store Error Message

if (isset($_POST['submit'])) {
if (empty($_POST['username']) || empty($_POST['password'])) {
$error = "Username or Password is invalid";
}
else
{

// Define $username and $password
$username=$_POST['username'];
$password=$_POST['password'];

// Establishing Connection with Server by passing server_name, user_id and password as a parameter

$connection = mysql_connect("localhost", "root", "password");

// To protect MySQL injection for Security purpose

$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);

// Selecting Database
$db = mysql_select_db("kike", $connection);
// SQL query to fetch information of registerd users and finds user match.

$query = mysql_query("select * from login where password='$password' AND username='$username'", $connection);
$rows = mysql_num_rows($query);

if ($rows == 1) {


$query = mysql_query("select * from login where password='$password' AND username='$username' AND admin = 1", $connection);
$master = mysql_num_rows($query);


     $_SESSION['login_user']=$username; // Initializing Session

        if($master == 1) { // some way of identifying an admin
            // admin

            header("location: wood/profile.php"); // Redirecting To Other Page
            exit;
        } else {
            // user
            header("location: user/profile.php");
            exit;
        }

$_SESSION["id"]= $user["id"];

            if(!empty($_POST["remember"])) {
                setcookie ("username",$_POST["username"],time()+ (10 * 365 * 24 * 60 * 60));
                setcookie ("password",$_POST["password"],time()+ (10 * 365 * 24 * 60 * 60));
            } else {
                if(isset($_COOKIE["username"])) {
                    setcookie ("username","");
                }
                if(isset($_COOKIE["password"])) {
                    setcookie ("password","");
                }
            }
                  } 

else {
$error = "Username or Password is invalid";

echo ' <div class="fixed-top">

<div class="alert alert-primary"  role="alert">
  Invalid username or password
</div> </div>' ;

}

mysql_close($connection); // Closing Connection
}
}
?>

</html>    

.警惕{
文本对齐:居中;
填充:12px;
背景色:#f44336;/*红色*/
颜色:白色;
边缘底部:10px;
}

我之前做了一个登录页面。。。希望它能帮助你。。。这是:


请注意,
mysql.*
函数自v5.5版(2013年6月)起被弃用,自v7.0版(2015年12月)起被删除。而是使用or。不要依赖
real\u escape\u string()
函数来阻止SQL注入。您应该通过或使用带绑定参数的准备语句。有一些很好的例子。永远不要存储纯文本密码。而是使用and.
session_start()将不起作用。它必须发生在任何空白或DOM呈现之前。为什么我的帖子没有帮助?