Login.php
は、それが」フォーム
<?php
include 'config/database.php';
include 'functions/functions.php';
$Db = "users";
$user = $_POST['emailaddress'];
$pass = $_POST['password'];
login($user, $pass, $con, $Db);
?>
のfunctions.php
if (!function_exists('login')) {
function login($user, $pass, $link, $db){
if(!$link->select_db($db)){
echo "Failed Database";
}
if(!empty($_POST)){
$person = sanitize($user, "html", $link);
$secret = sanitize($pass, "html", $link);
$query = "SELECT * FROM users WHERE email = ? AND pass = ?";
if (!$stmt = $link->prepare($query)) {
echo "Prepare failed: (" . $link->errno . ") " . $link->error;
}
$stmt->bind_param('ss', $person, $secret);
if (!$stmt->execute()) {
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
$result = $stmt->get_result();
$stmt->store_result();
$check = $result->num_rows;
if($check){
$items = $result->fetch_assoc();
session_start();
$_SESSION['loggedin'] = true;
echo "why cant it lead to view_record.php";
//header("Location: view_record.php");
}
else{
header("Location: index.php?error=true");
}
exit;
$query->free_result();
$link->close();
}
}
}
HTMLログイン
<form id="login" name="login-form" method="POST" action="login.php">
<div class="form-group">
<label for="emailaddress">Email address</label>
<input type="email" class="form-control" name="emailaddress" placeholder="Email Address">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" name="password" placeholder="Password">
</div>
<button type="submit" class="btn btn-login">Login</button>
</form>
エコーにログインするために戻って私をリダイレクトログインしようとするとview_record.phpにつながってしまいました。しかし、ヘッダーを使用すると、ページが表示されず、代わりにログインフォームページにリダイレクトされます。それが機能する前に、関数のログイン内でコードを変更し、それはもはや機能しません。なぜヘッダがもはや働いていないのか分かりません。
ヘルプありがとうございました!しかし、これはあなたの問題を解決しません
<?php
session_start();
include 'config/database.php';
include 'functions/functions.php';
$Db = "users";
$user = $_POST['emailaddress'];
$pass = $_POST['password'];
login($user, $pass, $con, $Db);
?>
Functions.php
if (!function_exists('login')) {
function login($user, $pass, $link, $db) {
if (!$link->select_db($db)) {
echo "Failed Database";
}
if (!empty($_POST)) {
$person = sanitize($user, "html", $link);
$secret = sanitize($pass, "html", $link);
$query = "SELECT * FROM users WHERE email = ? AND pass = ?";
if (!$stmt = $link->prepare($query)) {
echo "Prepare failed: (" . $link->errno . ") " . $link->error;
}
$stmt->bind_param('ss', $person, $secret);
if (!$stmt->execute()) {
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
$result = $stmt->get_result();
$stmt->store_result();
$check = $result->num_rows;
if ($check) {
$items = $result->fetch_assoc();
$_SESSION['loggedin'] = true;
echo "why cant it lead to view_record.php";
//header("Location: view_record.php");
// # -- Line added
exit;
} else {
header("Location: index.php?error=true");
// # -- Line added
exit;
}
// This exit is not necassary
exit;
// This will never be executed
$query->free_result();
$link->close();
}
}
}
: -
更新view_record.php
<body>
<?php include 'layout/header.php' ?>
<div class="container center-block">
<h1>View List</h1>
<?php
include 'config/database.php';
include 'functions/functions.php';
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) {
viewList("test", "id", $con);
}
else{
header("Location: index.php");
}
?>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
</body>
なぜそのコメントに? //ヘッダ( "Location:view_record.php"); – RJParikh
@RuchishParikh - はい私はヘッダーでテストして、ログインフォームに戻ってきました。そこで私は最初にコメントし、エコーが表示されているかどうかを調べました。それはうまくいったが問題はログインして確認してからページを見るために私にかかるはずだ。 – joe
スクリプトの先頭に 'session_start()'を実行する必要があります。 – Peter