arrays - 不同的密码如何重定向到 php 和 html 中的不同页面
问题描述
如何使用密码重定向到具有不同密码的不同页面。回声缺少一些东西,我想我应该添加一个数组。echo multiples 如何回显... Grrr 我有 3 个密码,想用这些密码重定向到 3 个不同的页面?
<?php
// Rename this file to config.php
$password05 = "fogy05";
$password10 = "fogy10";
$password20 = "fogy20";
$redirect05 = "download/05/index.html";
$redirect10 = "download/10/index.html";
$redirect20 = "download/20/index.html";
$require_https = true;
<?php
require_once("config.php");
if ($require_https && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] !== 'on')) {
if(!headers_sent()) {
header("Status: 301 Moved Permanently");
header(sprintf(
'Location: https://%s%s',
$_SERVER['HTTP_HOST'],
$_SERVER['REQUEST_URI']
));
exit();
}
}
if (isset($_POST['password'])) {
if ($_POST['password'] === $password05) {
$success = true;
}
elseif (strlen($_POST['password05']) == 0) {
$alert = "Password cannot be empty.";
}
else {
$alert = "Password incorrect. Please try again.";
}
}
?>
<?php if ($success) { ?><meta http-equiv="refresh" content="3;URL=<?php echo $redirect ?>"><?php } ?>
<form class="form-signin" role="form" method="POST">
<?php if ($success) { ?>
<div class="alert alert-success" role="alert"><b>Code valide. Redirection...</b></div>
<?php } else { ?>
<?php if(isset($alert)) { ?>
<div class="alert alert-danger" role="alert"><b><?php echo $alert ?></b></div>
<?php } ?>
<h2 class="form-signin-heading">Veuillez entrer votre code</h2>
<input type="password" name="password" class="form-control" placeholder="Password" autocomplete="off" autofocus>
<button class="btn btn-lg btn-primary btn-block" type="submit">Go</button>
<?php } ?>
</form>
</div>
解决方案
if (isset($_POST['password'])) {
if ($_POST['password'] === $password05) {
header("Location: {$redirect05}");
exit;
}
elseif ($_POST['password'] === $password10) {
header("Location: {$redirect10}");
exit;
}
elseif ($_POST['password'] === $password20) {
header("Location: {$redirect20}");
exit;
}
elseif (strlen($_POST['password']) == 0) {
$alert = "Password cannot be empty.";
}
else {
$alert = "Password incorrect. Please try again.";
}
}
您可以使用标头重定向
推荐阅读
- python - 'self' 参数和 python 请求模块的问题
- python - 为什么 statsmodels 和 sklearn 返回不同的 Lasso 估计值?
- python - NodeJS、Anaconda 和设置 NodePath(conda 不更新路径)
- c# - 处理目录中的所有文件
- python - Matplotlib:在绘图底部突出显示范围
- swiftui - SwiftUI:引用表示的视图控制器?
- javascript - javascript访问mssql数据库的繁琐代码
- java - How to compare a ZonedDateTime's time with another ZonedDateTime but with only time and not date?
- mlops - 诊断 FiftyOne 应用程序的崩溃 – 日志或其他工具
- python - Python plotly choropleth 地图可视化,未提供身份验证凭据错误