我正在使用一些包含登录php设置的新软件。工作正常,直到我决定在灯箱中打开登录页面。现在,我无法将灯箱打开到我的成功目标页面的普通视图浏览器页面。 php代码如下;
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['form_name']) && $_POST['form_name'] == 'loginform')
{
$success_page = './club_registered_breeders_only.php';
$error_page = './Error_form_failure.html';
$database = './usersdb.php';
$crypt_pass = md5($_POST['password']);
$found = false;
$fullname = '';
$session_timeout = 600;
if(filesize($database) > 0)
{
$items = file($database, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach($items as $line)
{
list($username, $password, $email, $name, $active) = explode('|', trim($line));
if ($username == $_POST['username'] && $active != "0" && $password == $crypt_pass)
{
$found = true;
$fullname = $name;
}
}
}
if($found == false)
{
header('Location: '.$error_page);
exit;
}
else
{
if (session_id() == "")
{
session_start();
}
$_SESSION['username'] = $_POST['username'];
$_SESSION['fullname'] = $fullname;
$_SESSION['expires_by'] = time() + $session_timeout;
$_SESSION['expires_timeout'] = $session_timeout;
$rememberme = isset($_POST['rememberme']) ? true : false;
if ($rememberme)
{
setcookie('username', $_POST['username'], time() + 3600*24*30);
setcookie('password', $_POST['password'], time() + 3600*24*30);
}
header('Location: '.$success_page);
exit;
}
}
$username = isset($_COOKIE['username']) ? $_COOKIE['username'] : '';
$password = isset($_COOKIE['password']) ? $_COOKIE['password'] : '';
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['form_name']) && $_POST['form_name'] == 'forgotpasswordform')
{
$email = isset($_POST['email']) ? addslashes($_POST['email']) : '';
$found = false;
$items = array();
$success_page = '';
$error_page = './Error_form_failure.html';
$database = './usersdb.php';
if (filesize($database) == 0 || empty($email))
{
header('Location: '.$error_page);
exit;
}
else
{
$items = file($database, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach($items as $line)
{
list($username, $password, $emailaddress, $fullname, $active) = explode('|', trim($line));
if ($email == $emailaddress && $active != "0")
{
$found = true;
}
}
}
if ($found == true)
{
$alphanum = array('a','b','c','d','e','f','g','h','i','j','k','m','n','o','p','q','r','s','t','u','v','x','y','z','A','B','C','D','E','F','G','H','I','J','K','M','N','P','Q','R','S','T','U','V','W','X','Y','Z','2','3','4','5','6','7','8','9');
$chars = sizeof($alphanum);
$a = time();
mt_srand($a);
for ($i=0; $i < 6; $i++)
{
$randnum = intval(mt_rand(0,55));
$newpassword .= $alphanum[$randnum];
}
$crypt_pass = md5($newpassword);
$file = fopen($database, 'w');
foreach($items as $line)
{
$values = explode('|', trim($line));
if ($email == $values[2])
{
$values[1] = $crypt_pass;
$line = '';
for ($i=0; $i < count($values); $i++)
{
if ($i != 0)
$line .= '|';
$line .= $values[$i];
}
}
fwrite($file, $line);
fwrite($file, "\r\n");
}
fclose($file);
$mailto = $_POST['email'];
$subject = 'New password';
$message = 'Your new password for Club Login is:';
$message .= $newpassword;
$header = "From: webmaster@whiteshepherdsnz.com"."\r\n";
$header .= "Reply-To: webmaster@whiteshepherdsnz.com"."\r\n";
$header .= "MIME-Version: 1.0"."\r\n";
$header .= "Content-Type: text/plain; charset=utf-8"."\r\n";
$header .= "Content-Transfer-Encoding: 8bit"."\r\n";
$header .= "X-Mailer: PHP v".phpversion();
mail($mailto, $subject, $message, $header);
header('Location: '.$success_page);
}
else
{
header('Location: '.$error_page);
}
exit;
}
?>
不知怎的,我需要设置target =&#34; -top&#34;因此,成功页面将在具有普通浏览器视图的同一窗口中打开。有人可以告诉我如何实现这一目标。我没有这方面的技能,只是通过阅读这些网站并应用于我的问题 谢谢 罗杰
答案 0 :(得分:3)
为了简短明了,您需要在网址中添加#
。
header("Location: index.php#top");
这会将您重定向到index.php
并将目标设置为#top
注意:请记住,header('Location: ...')
应该重定向到您在浏览器中使用的网址。不是内部服务器路径。
答案 1 :(得分:1)
尝试使用Window-target
header('Window-target: _top');
header('Location: index.php');
答案 2 :(得分:0)
不幸的是,WYSIWYG Web Builder只允许选择内部页面地址,不允许编辑,因此无法尝试。但是,在目标页面的头部使用Java脚本找到了另一种解决方案:
<script>
this.top.location !== this.location && (this.top.location = this.location);
</script>
这完美无缺。我将把您的意见传递给WYSIWYG Web Builder论坛。 感谢
答案 3 :(得分:-1)
如果您采用表格形式 您可以以这种形式放置目标。
<form action="" method="" target="_top">
<input type="" name="">
</form>