我正在学习PHP和HTML(抱歉是新手)试图将客户重定向到输入插入后的不同链接。这意味着在他按下验证后,他将被重定向到我的网站www.example.com/home.php这是我当前的代码:
<div class="tclpad" style="width:90px;"> </div>
<div class="tclpad"><input class="bstd" value="Verify" type="submit"></div>
另外,当有人插入错误的信息时,我可以在代码中看到:
<?php
if(isset($_SESSION['wrong'])) {
echo "<p class='error'>Authentication failed.</p>";
session_destroy();
}
?>
我希望用户在按下验证后会得到一条消息'已验证'。非常感谢你们的帮助。
检查这里接受的答案:如何在PHP中进行重定向?
我不确定你到底在寻找什么'Verified'语句,但上面的答案显示了如何用PHP header()函数重定向网页。
编辑:我意识到header()函数限制了当前页面提供反馈的方式。相反,您可以使用javascript重定向:
function redirectOnVerify(myVar) {
if(myVar === 'success'){
window.alert('You have verified successfully');
window.location = 'http://newlocation.com' ;
}
else if (myVar === 'failure') {
window.alert('Failed to verify');
}
else {
console.log('PHP auth error, neither success nor failure')
}
}
然后在html中:
<input onClick="redirectOnVerify('
<?php if(isset($_SESSION['right'])){
echo 'success'
}
else if (isset($_SESSION['wrong']){
echo 'failure'
}
else {}
?>
')">
/j
像
那样使用header()header("refersh: 2; url=page2url");
refsh在这里是一个延迟时间,页面将在2秒后重定向,如果你不想要延迟,那么要么将refsh设置为0,要么执行
header("location=pag2url");