大家好,请帮助我开发了我的第一个网站www.ncrwallpaper.com。 我的问题是每当我从登录页面登录时。 1,它不会重定向到目标页面 2已登录,但在当前页面中没有显示..
这是我的代码
<?php
session_start();
include('dbfunctions.php');
include_once('top.php');
if(isset($_POST['login'])) {
$a=$mysqli->real_escape_string($_POST['email']);
$b=$mysqli->real_escape_string($_POST['pass']);
$c=$mysqli->query("select * from users where email='$a' and pass='$b'");
$count=$c->num_rows;
if($count==1){
$f=$c->fetch_object();
//value assign in session_id
$_SESSION["id"]=$f->id;
$_SESSION["email"]=$f->email;
$_SESSION["name"]=$f->name;
$_SESSION["contact"]=$f->contact;
if(isset($_SESSION['url'])) $url = $_SESSION['url']; // holds url for last page visited.
else $url = "index.php";
header("Location: $url");
} else echo "Please enter valid email id and password";
}
?>
此代码已在localhost上运行
<form action="#" method="post" enctype="multipart/form-data">
<input type="email" name="email" placeholder="E-Mail Address" id="input-email" class="form-control" required autofocus/>
<input type="password" name="pass" placeholder="Password" id="input-password" class="form-control" required/>
<input type="submit" value="Login" class="btn btn-primary" name="login" />
</form>
答案 0 :(得分:1)
在header
输出您使用的javascript ,output buffering或元刷新选项top.php
中的css之后,您无法使用echo '<meta http-equiv="refresh" content="0; URL=' . $url . '">';
0
<?xml version="1.0" encoding="UTF-8"?>
<doc>
<ticker> CSGN.VX </ticker>
<stockExchange> NYSE </stockExchange>
<stockDatas>
<stockData>
<date>2015-08-06</date>
<closingPrice>140</closingPrice>
</stockData>
<stockData>
<date>2015-08-07</date>
<closingPrice>140.25</closingPrice>
</stockData>
<stockData>
<date>2015-08-10</date>
<closingPrice>140.75</closingPrice>
</stockData>
</stockDatas>
</doc>
是网站在刷新前应显示的延迟时间
答案 1 :(得分:1)
您可以使用ob_start()
&amp; ob_end_clean()
<?php
ob_start();
session_start();
include('dbfunctions.php');
include_once('top.php');
if(isset($_POST['login'])) {
$a=$mysqli->real_escape_string($_POST['email']);
$b=$mysqli->real_escape_string($_POST['pass']);
$c=$mysqli->query("select * from users where email='$a' and pass='$b'");
$count=$c->num_rows;
if($count==1){
$f=$c->fetch_object();
//value assign in session_id
$_SESSION["id"]=$f->id;
$_SESSION["email"]=$f->email;
$_SESSION["name"]=$f->name;
$_SESSION["contact"]=$f->contact;
if(isset($_SESSION['url'])) $url = $_SESSION['url']; // holds url for last page visited.
else $url = "index.php";
$output = ob_get_contents();
ob_end_clean();
header("Location: $url");
} else echo "Please enter valid email id and password";
}
?>
答案 2 :(得分:0)
尝试使用此代替您的标题
<script type="text/javascript">
window.location.assign('your desired location');
</script>
注意:在脚本标记之前关闭php并在关闭脚本标记后打开php
答案 3 :(得分:0)
<?php
session_start();
include('dbfunctions.php');
?>
<?php include_once('top.php'); ?>
<?php
if(isset($_POST['login']))
{
$a=$mysqli->real_escape_string($_POST['email']);
$b=$mysqli->real_escape_string($_POST['pass']);
$c=$mysqli->query("select * from users where email='$a' and pass='$b'");
$count=$c->num_rows;
if($count==1){
$f=$c->fetch_object();
//value assign in session_id
$_SESSION["id"]=$f->id;
$_SESSION["email"]=$f->email;
$_SESSION["name"]=$f->name;
$_SESSION["contact"]=$f->contact;
if(isset($_SESSION['url']))
$url = $_SESSION['url']; // holds url for last page visited.
else
$url = "index.php";
echo " <script type=\"text/javascript\">
window.location.assign('blaahh.php');
</script> ";
}
else{
echo "Please enter valid email id and password";
}
}
?>
答案 4 :(得分:0)
你需要一些JS。只需将此代码放在标题中:
?> // close php
<script type="text/javascript">
window.location.assign('location');
</script>
<?php // open php again
答案 5 :(得分:0)
<强> PHP:强>
header("Location: yourpage.php");
exit;
您必须在标题后使用exit或die才能停止执行代码。此外,代码必须在任何输出之前执行。