私はphpに新しいですし、私は登録し、ページにログインしようとしています。Loggin in PHPが動作しません
私は新しいユーザーとして登録すると正常に動作し、データベースに表示されます。しかし、ログインする際には、私はすべてを試した問題があるようです。
私がしたいのは、ユーザーがログインしてホームページにリダイレクトするときです。ログイン情報が間違っていると、エラーメッセージが表示されます。ここで
は、ファイル内のログにあるPHPコードは次のとおりです。
<?php
session_start();
if(isset($_SESSION['users_id']) ){
header("Location: /");
}
require 'database.php';
if(!empty($_POST['email']) && !empty($_POST['password'])):
$records = $conn->prepare('SELECT id,email,password FROM users WHERE email = :email');
$records->bindParam(':email', $_POST['email']);
$records->execute();
$results = $records->fetch(PDO::FETCH_ASSOC);
$message = '';
if(count($results) > 0 && password_verify($_POST['password'], $results['password']) )
{
$_SESSION['users_id'] = $results['id'];
header("Location: php.dev/index.php", true, 301); exit();
}
else {
$message = 'Sorry, thoes credentials do not match';
}
endif;
?>
header("Location:....)
これが動作するようには思えません。私は本当にここに何か助けてくれる?ここで
はhtmlコードは次のとおりです。
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Login</title>
<link href="Style/phpstyle.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet">
</head>
<body>
<div class="header">
<a href="php.dev/index.php"> TIPBUCKET </a>
</div>
<?php if(!empty($message)): ?>
<p><?= $message ?></p>
<?php endif; ?>
<h1>Login</h1>
<span> or <a href="register.php">Register here</a></span>
<form action="login.php" method="POST">
<input type="text" placeholder="enter your email" name="email">
<input type="password" placeholder="Password" name="password">
<input type="submit">
</form>
</body>
</html>
は、任意の回答に事前にありがとう:)
'php.dev/index.php'とは何ですか?確かにそれはURLではありません... – arkascha
私はローカルホストMAMPを使用していますので、現在のURLはphp.devでindex.phpはホームページです – user3719086
有効なURLは 'http://php.dev/ index.php'。 'php.dev/index.php'はドットとスラッシュを含む任意の文字列です。 – arkascha