這裏是我的形式使用的login.php檢查用戶是否註冊等PHP變化後的目標時,用戶登錄成功
<form action="login.php" method="post" target="SHOW">
<ul id="login">
<li>
Username:<br />
<input type="text" name="username">
</li>
<li>
Password:<br />
<input type="password" name="password">
</li>
<li>
Submit:
<br />
<input type="submit" name="log in">
</li>
<li>
<a href="../../register.php">Register</a></li>
</ul>
</form>
<iframe id="iframe" name="SHOW" scrolling="no"></iframe>
我的困境與我使用的iframe標籤莖顯示錯誤消息。如果用戶已註冊,我想將他重定向回index.php,就像您在PHP ---> header('Location:index.php')結尾處看到的一樣。
問題是iframe不允許重定向。所以,我想將目標從---> target =「SHOW」改爲target =「_ top」或類似的東西。因此,用戶在成功登錄後重定向,而不使用任何JavaScript。
我在嘗試完成此操作時失敗 - > $ href-> removeAttribute('target'); $ href-> setAttribute(「target」,「_top」);
這裏是login.php。
<?php
include 'core/init.php';
if(empty($_POST) === false){
$username = $_POST['username'];
$password = $_POST['password'];
if(empty($username) || empty($password) === true){
$errors[] = 'You need to enter a username and password';
} else if (user_exists($username) === false){
$errors[] = 'We can\'t find that username. Have you registered?';
} else if (user_active($username) === false){
$errors[] = 'You haven\'t activated your account!';
} else {
$login = login($username, $password);
if($login === false){
$errors[] = 'That username/password combination is incorrect';
} else {
$_SESSION['user_id'] = $login;
$href->removeAttribute('target');
$href->setAttribute("target", "_top");
header('Location: index.php');
exit();
}
}
print_r($errors);
}
?>
你試過header('Location:index.php');在頁面頂部只是爲了檢查它是否正常工作 – knightrider
header('Location:index.php');工作正常,但是,它張貼在iframe中,根本沒有用。在網頁內部創建一個迷你窗口。 –