私は、ログインページにユーザーを追加しようとしていますが、それはページ自体にリダイレクト
login.php
<?php
include './connect.php';
session_start();
if (($_SERVER["REQUEST_METHOD"] == "POST") && (!empty($_POST['username'])) && (!empty($_POST['password']))) {
$postedUsername = $_POST['username'];
$postedPassword = $_POST['password'];
$userDatabaseFind = $database->login->findOne(array('username' => $postedUsername, 'password' => $postedPassword));
$storedUsername = $userDatabaseFind['username'];
$storedPassword = $userDatabaseFind['password'];
if (($postedUsername == $storedUsername) && ($postedPassword == $storedPassword)) {
$_SESSION['username'] = $storedUsername;
if($_SESSION['username'] == 'admin'){
session_regenerate_id();
header('location:printDetail.php');
}
else{
session_regenerate_id();
header('location:welcome.php');
}
} else {
echo 'Error';
}
}
printDetail.php
コードではありませんリダイレクトがなくてもリダイレクトし続けます<?php
require './connect.php';
require './login.php';
//SEARCHING ACROSS THE COLLECTIONS IN THE DATABASE
$printDetailCollections = $database->details;
$printDetailCursor = $printDetailCollections->find();
//INITIALIZE THE VALUE TO ZERO SO IT CAN GO THROUGH THE DATABASE
$i = 0;
//USERNAME AND PASSWORD ARE CHECKED IF IT IS ASSIGNRD THEN THE SESSION IS DISPLAYED
if (isset($_SESSION['username']) && !(empty($_SESSION['username']))) {
//LOOP FOR TRAVERSING ACROSS THE DATABASE
foreach ($printDetailCursor as $doc) {
$i++;
}
} else {
header('location:index.html');
}
?>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 15px;
}
body{
background-image: url(images/16386858141_65a65879cd_b.jpg);
background-repeat: no-repeat;
background-size: cover;
}
</style>
<script>
$(document).ready(function() {
window.onload = $('#table').hide();
});
</script>
</head>
<body>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Business card Management</a>
</div>
<ul class="nav navbar-nav">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Menu
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="addUser.php">Add entry</a></li>
<li><a href="#">Delete entry</a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="logout.php"><span class="glyphicon glyphicon-log-out"></span> Log out</a></li>
</ul>
</div>
</nav>
<div class="container">
<table id="table">
<thead>
<tr>
<th>First Name</th>
<th>Second Name</th>
<th>Company Name</th>
<th>Designation</th>
</tr>
</thead>
<tbody>
<?php
foreach ($printDetailCursor as $printDetailDocument) {
?>
<tr>
<td>
<?php
echo (json_decode($printDetailDocument['First Name']));
?>
</td>
<td>
<?php
echo (json_decode($printDetailDocument['Second Name']));
?>
</td>
<td>
<?php
echo (json_decode($printDetailDocument['Company Name']));
?>
</td>
<td>
<?php
echo (json_decode($printDetailDocument['Designation']));
}
?>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
私はMongoDBのログインに3つのコレクションを持っているとdetails.Theユーザーを追加、ユーザー
を追加するためのログインコレクションにアクセスしようとしますaddUser.phpコード
に誤りを見つけ出すことができなかった私はURL 経由printDetail.phpへのアクセスを無効にしようとしていると私はそれがredirection.But主な理由だと思う<?php
include './connect.php';
$username = NULL;
$password = NULL;
$confPassword = NULL;
$passwordError = "";
$userEntryCollection = NULL;
if (isset($_SESSION['username']) && !(empty($_SESSION['username']))) {
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$userEntryCollection = $database->login;
if (isset($_POST['username'])) {
$username = $_POST['username'];
}
if (isset($_POST['password'])) {
$password = $_POST['password'];
}
if (isset($_POST['confPassword'])) {
$confPassword = $_POST['confPassword'];
}
} else {
echo 'error';
}
if ($password != $confPassword) {
$passwordError = "Your passwords doesnot match";
} else {
$userEntry = array(
"username" => $username,
"password" => $password,
);
$userEntryCollection->insert($userEntry);
}
}
?>
<html>
<head>
<link rel="stylesheet" href=bootstrap-3.3.7-dist/css/bootstrap.min.css>
<script src="bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<style>
.col-lg-10{
position: relative;
width: 350px;
border-radius: 25px;
}
form{
position: absolute;
top: 10%;
left: 40%;
}
body{
background-image: url(images/16386858141_65a65879cd_b.jpg);
background-repeat: no-repeat;
background-size: cover;
}
form{
color: black;
}
</style>
</head>
<body>
<nav class="navbar navbar-inverse">
<ul class="nav navbar-nav navbar-left">
<li><a href="printDetail.php"><span class="glyphicon glyphicon-arrow-left">Back</span></li>
</ul>
</nav>
<form method="POST" class="col-lg-10" <?php echo $passwordError; ?> >
<div class="form-group form-inline"><br>
<label for="firstName">Username</label><br>
<input type="text" class="form-control" id="username" name="username">
</div>
<div class="form-group form-inline">
<label for="secondName">Password:</label><br>
<input type=password class="form-control" id="password" name="password">
</div>
<div class="form-group form-inline">
<label for="secondName">Confirm Password</label><br>
<input type=password class="form-control" id="confPassword" name="confPassword">
</div>
<button type="button" class="btn btn-success">Submit</button>
</form>
</body>
</html>
ページは、ユーザー名
Psとのフィールドをクリックすることで、単にリダイレクトされます:私はこのように保存されたパスワードが
'index.php'で何ですか? – imrealashu
usernameとpwdエントリのhtmlテンプレートがありません – abhishek
'session_regenerate_id();'が 'isset($ _ SESSION ['username'])を持たない理由ではないと思いませんか? 'printDetail.php? –