2016-06-27 6 views
-1

Die Codes für Website ist unten angegeben. Login kann nicht mit dem, was ich getan habe, authentifiziert werden. Erstens wird es wie erwartet auf die Anmeldeseite umgeleitet, wenn es nicht eingeloggt ist. Dann, nachdem ich die Login-Daten klar angegeben habe, wird es mich nicht zu der gewünschten Seite weiterleiten. Stattdessen bleibt es auf der Anmeldeseite. Bitte helfen Sie mir ...Login-Authentifizierung funktioniert nicht für meine Website

<!--This is the page that I want to redirect after successful login--> 
 

 

 
<?php 
 
session_start(); 
 

 
if($_SESSION['loggedIn']) 
 
{ 
 
    header('Location: restaurant.php'); 
 
} 
 
else 
 
{ 
 
    header('Location: login.php'); 
 
} 
 
?> 
 

 
<html lang="en"> 
 
<head> 
 
    <title>Welcome to Foodline</title> 
 
    <meta charset="utf-8"> 
 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
 
    <meta name="description" content=""> 
 
    <meta name="author" content=""> 
 
    <link rel="stylesheet" href="bootstrap/dist/css/bootstrap.min.css"> 
 
    <link href="css/simple-sidebar.css" rel="stylesheet"> 
 

 
    <script src="bootstrap/js/jquery.min.js"></script> 
 
    <script src="bootstrap/js/bootstrap.min.js"></script> 
 
    <script type="text/javascript" src="js.js"></script> 
 
    <script type="text/javascript" src="jquery.js"></script> 
 

 
    <style> 
 
    /* Remove the jumbotron's default bottom margin */ 
 
    .jumbotron { 
 
     margin-bottom: 0; 
 
    } 
 
    
 
    /* Add a gray background color and some padding to the footer */ 
 
    footer { 
 
\t background-color: #f2f2f2; 
 
     padding: 25px; 
 
    } 
 
    </style> 
 
</head> 
 
<body> 
 

 
<div class="jumbotron"> 
 
    <div class="container text-center"> 
 
    <h1><font face="Analecta">FOODLINE</font></h1> 
 
    <p>We provide the best service for our costumers</p> 
 
    </div> 
 
</div> 
 

 
<nav class="navbar navbar-inverse" data-spy="affix" data-offset-top="197"> 
 
    <div class="container-fluid"> 
 
    <div class="navbar-header"> 
 
    <a class="navbar-brand"><font face="Analecta" color="white">>Restaurants<</font></a> 
 
    </div> 
 

 
    <div class="collapse navbar-collapse" id="myNavbar"> 
 
     <ul class="nav navbar-nav"> 
 
       <li> 
 
        <a href="foodline.php">Hamro Didi (HD)</a> 
 
       </li> 
 
       <li> 
 
        <a href="#">HK</a> 
 
       </li> 
 
       <li> 
 
        <a href="#">Junu Hotel</a> 
 
       </li> 
 
       <li> 
 
        <a href="#">Junction Cafe</a> 
 
       </li> 
 
       <li> 
 
        <a href="#">Laxmi Hotel</a> 
 
       </li> 
 
      </ul> 
 
     </div> 
 
    </div> 
 
    </nav> 
 

 

 
<footer class="container-fluid text-center"> 
 
<p>Foodline Official Website &copy</p> 
 
<p align="center">Logged in as: <div id="username" align="center"> <span class="glyphicon glyphicon-log-in"></span><?php 
 
if(isset($_GET['id'])){ 
 
echo ' '.$_GET['id']; 
 
} 
 
else { 
 
echo '(write) a 404 page'; 
 
} 
 
?> 
 
</div> 
 
</p> 
 
</footer> 
 

 
</div>

<!--This is login.php--> 
 

 

 
<?php 
 
//session_start(); 
 
include("connection.php"); 
 
$msg=''; 
 

 
if($_SERVER["REQUEST_METHOD"] == "POST") 
 
{ 
 
    // username and password sent from form 
 
    $username = $_POST['username']; 
 
    $password = $_POST['password']; 
 

 
    // To protect MySQL injection 
 
    $username = stripslashes($username); 
 
    $password = stripslashes($password); 
 
    $username = mysql_real_escape_string($username); 
 
    $password = mysql_real_escape_string($password); 
 

 
    //Input Validations 
 
    if($username == '') { 
 

 
$_SESSION["login_user"] = $username; $msg = "Username missing"; 
 
    header("location: login.php?msg=$msg"); 
 
    } 
 
    if($password == '') { 
 
    $msg = "Password missing"; 
 
    header("location: login.php?msg=$msg"); 
 
    } 
 
    //Create query 
 
    $qry="SELECT * FROM user WHERE user_name='$username' AND user_password='$password'"; 
 
    $result =mysql_query($qry)or die(mysql_error()); 
 
    $output=mysql_fetch_assoc($result); 
 
    //Check whether the query was successful or not 
 
     if(!empty($output)) { 
 
     //Login Successful 
 
     $_SESSION['name']= $username; 
 
     $_SESSION['loggedIn'] = true; 
 
     header("location:restaurant.php?id=$username"); 
 
     
 
    } 
 
    else { 
 
     //Login failed 
 
     $msg= "user name and password not found"; 
 
     header("location:login.php?msg=$msg"); 
 
     
 
     } 
 
} 
 
?> 
 

 

 
<html> 
 
<head> 
 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
 
    <link rel="stylesheet" href="bootstrap/dist/css/bootstrap.min.css"> 
 
    <script src="bootstrap/js/jquery.min.js"></script> 
 
    <script src="bootstrap/js/bootstrap.min.js"></script> 
 
    
 
    <style> 
 
    .jumbotron { 
 
     margin-bottom: 0; 
 
    } 
 
    </style> 
 
</head> 
 
<body> 
 

 
<div class="jumbotron"> 
 
    <div class="container text-center"> 
 
    <h1><font face="Analecta">FOODLINE</font></h1>  
 
    <p>We provide the best service for our costumers</p> 
 
    </div> 
 
</div> 
 

 
<nav class="navbar navbar-inverse" data-spy="affix" data-offset-top="197"> 
 
    <div class="container-fluid"> 
 
    <div class="navbar-header"> 
 
    <a class="navbar-brand" href="index.php">Logo</a> 
 
    </div> 
 
    <div class="collapse navbar-collapse" id="myNavbar"> 
 
     <ul class="nav navbar-nav"> 
 
     <li class="active"><a href="index.php">Home</a></li> 
 
     <li><a href="restaurant.php">Restaurants</a></li> 
 
     
 
     <li><a href="contact-form/index.html">Contact</a></li> 
 
     </ul> 
 
    <ul class="nav navbar-nav navbar-right"> 
 
     <li><a href="register.php"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li> 
 
     <li><a href="login.php"><span class="glyphicon glyphicon-log-in"></span> Login</a></li> 
 
    </ul> 
 
    </div> 
 
    </div> 
 
</nav> 
 

 
<div class="container"> 
 
    <h2><font face="Analecta">>Login from here<</font></h2> 
 
    <form role="form" name="login" action="login.php" method="post" accept-charset="utf-8"> 
 
    <div class="form-group"> 
 
     <label for="username">Username:</label> 
 
     <input type="text" class="form-control" name="username" placeholder="Enter username" required> 
 
    </div> 
 
    <div class="form-group"> 
 
     <label for="password">Password:</label> 
 
     <input type="password" class="form-control" name="password" placeholder="Enter password" required> 
 
    </div> 
 
    <div class="checkbox"> 
 
     <label><input type="checkbox"> Remember me</label> 
 
    </div> 
 
    <button type="submit" class="btn btn-default" value="login">Submit</button> 
 
    <br> 
 
    <br> 
 
    
 
    <?php 
 
     $msg = (isset($_GET['msg']) ? $_GET['msg'] : null); //GET the message 
 
     if($msg!='') echo '<p>'.$msg.'</p>'; //If message is set echo it 
 
    ?> 
 
    
 
    </form> 
 
    <p>Not a user yet? Sign up <a href="register.php">here</a></p> 
 
</div> 
 

 
<footer class="container-fluid text-center"> 
 
    <p>Foodline Official Website &copy</p> 
 
    <p>Get deals: 
 
    <a href="register.php"><span class="glyphicon glyphicon-menu-right"></span>SignUp</a> 
 
    </p> 
 
</footer> 
 

 
</body> 
 
</html>

+0

'mysql_ *' Funktionen sind veraltet seit PHP 5.5 (und ** vollständig entfernt ** in PHP 7) und Sie sollten [aufhören, sie zu verwenden] (http://stackoverflow.com/q/12859942), wenn Sie können. Sie sollten eine andere API wählen, mit der Sie vorbereitete Anweisungen verwenden können (was Sie * wirklich sollten *), wie zB 'mysqli_ *' oder PDO - siehe [API wählen] (http://php.net/manual/en/mysqlinfo .api.choosing.php). Sie sollten auch ** wirklich, wirklich ** Ihr Passwort hashen, und vermeiden Sie alte Methoden wie 'sha1' oder' md5', verwenden Sie etwas wie ['password_hash()'] (http://php.net/manual/en /function.password-hash.php) stattdessen. – Qirel

Antwort

2

Kommentar-:

//session_start(); 

Von Linie 5 in login.php und diese ändern:

if(! $_SESSION['loggedIn']) { 
    header('Location: login.php'); 
} 

in restaurant.php.

+0

Danke für die Antwort, aber es zeigte so etwas wie up „Die localhost Seite funktioniert nicht localhost Sie zu oft umgeleitet. ERR_TOO_MANY_REDIRECTS“ in meinem Browser ... –

+0

@ManishRajSilwal, die ein ziemlich expliziten Fehler ist. Setzen Sie sich einfach hin und überprüfen Sie jeden "Header-Standort". Benötigen Sie zum Beispiel eine 'header ('Location: resturaunt.php'' in der Datei' restaurant.php'? Was wäre das? – apokryfos

+0

Ändern Sie den Anfang von restaurant.php in: ' ' –