上传到服务器后登录页面无效

时间:2015-08-15 13:47:08

标签: php mysql

我使用localhost和不同类型的验证创建了一个登录页面。现在我的登录页面在localhost(wamp)上完美运行。但是当我将其上传到服务器时,登录页面不起作用。

不知道错误的原因是什么,但服务器不允许我登录网站。网站是由我自定义开发的。请帮我解决。

请帮我解决这个问题。

的index.php

<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>
<!DOCTYPE html>
<html>
<head>
<title>Admin Login</title>
<!-- Bootstrap -->
<link href="../css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="../css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
<link href="../css/custom_style.css" rel="stylesheet" media="screen">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body id="login">
<div class="top-logo"><img src="../assets/logo.png"></div>
<div class="container">
<div class="align_form_center">
<form  method="POST">
<div class="signin-heading"> Please sign in as <b>ADMIN</b></div>
<div class="align-center">
<!-- username box -->
<div class="form-group has-success has-feedback">
<div class="input-group col-md-10">
<span class="input-group-addon">Username</span>
<input type="text" name="admin_user" class="form-control" id="inputGroupSuccess5" aria-describedby="inputGroupSuccess3Status" required>
</div>
</br>
<!-- password box -->       
<div class="form-group has-success has-feedback">
<div class="input-group col-md-10">
<span class="input-group-addon">Password</span>
<input type="password" name="admin_pass" class="form-control" id="inputGroupSuccess3" aria-describedby="inputGroupSuccess3Status" required>
</div>
</br>     
<button name="submit" class="btn btn-large btn-primary col-md-10" type="submit">Sign in</button>
<br>
<label class="">
<input type="checkbox" value="remember-me"> Remember me
</label>
</div></div></div>
</form>
</div>  <!--align_form_center end-->
<footer>Site Design and Coded By <a href="www.freelancer.com/u/xbraindesigner.html">Xbraindesigner</a></footer>
</div> <!-- /container -->
<?php
include("../php/database_connection.php");
if(isset($_POST["submit"])){
$user=($_POST['admin_user']);
$pass=($_POST['admin_pass']);
if(isset($_POST['admin_user'])){$user=$_POST['admin_user'];}
if(isset($_POST['admin_pass'])){$pass=$_POST['admin_pass'];}
$user=stripslashes($user);
$pass=stripslashes($pass);
$user=mysqli_real_escape_string($con,$user);
$pass=mysqli_real_escape_string($con,$pass);
$result=mysqli_query($con,"SELECT * FROM admin_login WHERE admin_user='$user' AND admin_pass='$pass'")or die(mysqli_error());
$count=mysqli_num_rows($result);
if($result === FALSE){
echo ("query not working.".mysql_error());// better error handling
}
if($user=="" AND $pass=""){
return true;
}
if(isset($_POST['submit'])){
if($count == 1){
$_SESSION['admin_username'] = $user;
header("Location:profile.php");
exit;
}
else{
echo "Wrong Username or Password";
}
$result->close();
mysqli_close($con);
}}?>
<script src="../js/jquery-1.9.1.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
</body>
</html>

session_check.php

<?php
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
include("../php/database_connection.php");
session_start();// Starting Session
// Storing Session
$user_check=$_SESSION['admin_username'];
// SQL Query To Fetch Complete Information Of User
$ses_sql=mysqli_query($con,"select admin_user from admin_login where admin_user='$user_check'");
$row = mysqli_fetch_array($ses_sql);
$login_session =$row['admin_user'];
if(!isset($login_session)){
mysql_close($con); // Closing Connection
header('Location: index.php'); // Redirecting To Home Page
}
?>

profile.php

<?php 
include("session_check.php");
?>
<b id="welcome">Welcome : <i><?php echo $login_session; ?></i></b>

2 个答案:

答案 0 :(得分:0)

通过在feof()文件的顶部添加一些额外的函数来解决错误。

index.php

将此代码添加到登录页面的最顶层后,它解决了标题错误:

  

警告无法修改标头信息 - 标头已发送....等等

答案 1 :(得分:0)

在您已解决的答案中,我认为您已经错过了实际上真正的问题,那就是header()重定向的位置。在HTML内容呈现到页面之前,它必须移到顶部。 php中有各种各样的标题,所以如果你能正确放置标题,你将来不必使用缓冲区来解决标题错误:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include("../php/database_connection.php");

// I think using a function for this process will clean up your script a bit.
// Also moving it to an include page instead of on the page would also help de-clutter your login page.
function ValidateUser($username = false,$password = false,$con)
    {
        // Do all the sanitizing and such
        $username   =   mysqli_real_escape_string($con,trim(stripslashes($username)));
        $password   =   mysqli_real_escape_string($con,trim(stripslashes($password)));
        // Set a default error
        $success    =   array('success'=>false,'error'=>"invalid");
        // Check if the values after sanitizing are empty
        if(!empty($username) && !empty($password)) {
                // Fetch from the table
                $result     =   mysqli_query($con,"SELECT * FROM admin_login WHERE admin_user='$username' AND admin_pass='$password'") or die(mysqli_error($con));
                if($result) {
                    // If user in system true, if not false
                    $validuser  =   (mysqli_num_rows($result) == 1)? true:false;
                    $success    =   array('success'=>$validuser,'error'=> ((!$validuser)? "Invalid Username / Password": ""));
                    $result->close();
                }
                else
                    $success    =   array("success"=>false,"error"=>mysql_error());
            }
        // By now there will be a clear picture of validation
        return (object) $success; 
    }

session_start();
// You may want to do a redirect here if a user is already logged in:
if(!empty($_SESSION['admin_username'])) {
    header("Location:profile.php");
    exit;
}

// Just set a default error
$error  =   false;
// If submitted
if(isset($_POST["submit"])){
    // Check the user
    $validate   =   ValidateUser($_POST['admin_user'],$_POST['admin_pass'],$con);
    // If true
    if($validate->success) {
        // Assign session
        $_SESSION['admin_username'] = htmlspecialchars($_POST['admin_user'],ENT_QUOTES);
        // Redirect
        header("Location:profile.php");
        exit;
    }
    // Set the error again
    $error  =   $validate->error;
}
?><!DOCTYPE html>
<html>
<head>
    <title>Admin Login</title>
    <!-- Bootstrap -->
    <link href="../css/bootstrap.min.css" rel="stylesheet" media="screen">
    <link href="../css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
    <link href="../css/custom_style.css" rel="stylesheet" media="screen">
    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
</head>
<body id="login">
    <div class="top-logo"><img src="../assets/logo.png"></div>
    <div class="container">
        <div class="align_form_center">
            <form  method="POST">
                <div class="signin-heading"> Please sign in as <b>ADMIN</b></div>
                <div class="align-center">
                    <!-- username box -->
                    <div class="form-group has-success has-feedback">
                        <div class="input-group col-md-10">
                            <span class="input-group-addon">Username</span>
                            <input type="text" name="admin_user" class="form-control" id="inputGroupSuccess5" aria-describedby="inputGroupSuccess3Status" required>
                        </div>
                        </br>
                        <!-- password box -->       
                        <div class="form-group has-success has-feedback">
                            <div class="input-group col-md-10">
                                <span class="input-group-addon">Password</span>
                                <input type="password" name="admin_pass" class="form-control" id="inputGroupSuccess3" aria-describedby="inputGroupSuccess3Status" required>
                            </div>
                            </br>     
                            <button name="submit" class="btn btn-large btn-primary col-md-10" type="submit">Sign in</button>
                            <br>
                            <label class="">
                            <input type="checkbox" value="remember-me"> Remember me
                            </label>
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <!--align_form_center end-->
        <footer>Site Design and Coded By <a href="www.freelancer.com/u/xbraindesigner.html">Xbraindesigner</a></footer>
    </div>
    <!-- /container -->
    <?php echo $error; ?>
    <script src="../js/jquery-1.9.1.min.js"></script>
    <script src="../js/bootstrap.min.js"></script>
</body>
</html>
<?php mysqli_close($con); ?>