【发布时间】:2015-10-25 01:55:34
【问题描述】:
我正在尝试发送 SMS OTP 并从用户那里检索它以验证用户。 我的 SMS 脚本工作正常,但我无法存储会话变量并检查该特定用户的 OTP 是否有效。
index.php
<?php
$otp1 = '';
for($i=4;$i>0;$i--)
{
$otp1 = $otp1.chr(rand(48,57));
}
// SMS script here (working fine)
?>
<form action="process.php" method="post">
Enter OTP: <br>
<input type="number" name="otp2" >
<br>
<? php
session_start();
$_SESSION['otpnuser'] = 1;
$_SESSION['secretpassword'] = $otp1;
$_SESSION["otp2"] = $otp1;
?>
<input type="submit">
</form>
process.php
<?php
session_start();
if($_POST["otp2"] == $_SESSION["otp2"])
{
$_SESSION['otpuser'] = 1;
header("Refresh: 2; URL=success.php");
}
else
{
$_SESSION['otpuser'] = 0;
header("Refresh: 2; URL=fail.php");
}
?>
即使 OTP 正确,它总是将我重定向到 fail.php 页面。
【问题讨论】:
-
你在哪里声明
$_SESSION["otp2"]在你的 index.php 中? -
$_SESSION["otp2"] = $otp1;应该在 index.php 页面中声明??
标签: php forms session session-variables