0 レビュー
1 回答
php-検証条件
値が一致する場合は成功メッセージが表示され、ユーザーをインデックスページにリダイレクトする条件を作成したいのですが、値が一致しない場合は現在のページにとどまり、エラーメッセージを表示します。
login.php
<?php
//If input set then check if user input matches store details
if(isset($_POST) and $_POST)
{
$success = false;
$email = $_POST['email'];
$pass = $_POST['pass'];
$success = login($_POST['email'],$_POST['pass']);
//If successful display alert, redirect to index page
if(isset($success))
{
$success = true;
echo "<script type='text/javascript'>alert('Login successful\nRedirecting now.')</script>";
header('Location: index.php');
die();
}
//If unsuccessful display alert
else
{
echo "<script type='text/javascript'>alert('Login failed!')</script>";
}
}
?>
configure.php
<?php
//Define constants
define("EMAILAD", "[email protected]");
define("PASSWORD", "pwd");
//Create function to compare input to constants
function login($email, $pass)
{
$success = false;
if(($email == EMAILAD) && ($pass == PASSWORD))
{
$success = true;
}
return $success;
}?>
<?php
//If input set then check if user input matches store details
if(isset($_POST) and $_POST)
{
$success = false;
$email = $_POST['email'];
$pass = $_POST['pass'];
$success = login($_POST['email'],$_POST['pass']);
//If successful display alert, redirect to index page
if(isset($success))
{
$success = true;
echo "<script type='text/javascript'>alert('Login successful\nRedirecting now.')</script>";
header('Location: index.php');
die();
}
//If unsuccessful display alert
else
{
echo "<script type='text/javascript'>alert('Login failed!')</script>";
}
}
?>
<?php
//Define constants
define("EMAILAD", "[email protected]");
define("PASSWORD", "pwd");
//Create function to compare input to constants
function login($email, $pass)
{
$success = false;
if(($email == EMAILAD) && ($pass == PASSWORD))
{
$success = true;
}
return $success;
}?>
現時点では、インデックスページにリダイレクトするだけですが、どこが間違っているのか誰かに教えてもらえますか?
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。