Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
登录页面在PHP中不重定向到目标位置?_Php - Fatal编程技术网

登录页面在PHP中不重定向到目标位置?

登录页面在PHP中不重定向到目标位置?,php,Php,大家好,请帮助我开发了我的第一个网站www.ncrwallper.com,它正在测试中。 我的问题是,每当我从登录页面登录时。 第一,它不能重定向到目标页面 第二,其已登录,但在当前页面中未显示 这是我的密码 <?php session_start(); include('dbfunctions.php'); include_once('top.php'); if(isset($_POST['login'])) { $a=$mysqli->real_escape_strin

大家好,请帮助我开发了我的第一个网站www.ncrwallper.com,它正在测试中。 我的问题是,每当我从登录页面登录时。 第一,它不能重定向到目标页面 第二,其已登录,但在当前页面中未显示

这是我的密码

<?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";
}

?>
此代码已在本地主机上运行

<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>    

试着用这个代替你的标题

<script type="text/javascript">
window.location.assign('your desired location');
</script>

注意:在脚本标记之前关闭php,在关闭脚本标记之后打开php,您将需要一些JS。只需将此代码放在标题中:

<?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";
}

}

?>
 ?> // close php
<script type="text/javascript">
window.location.assign('location');
</script>
<?php // open php again
您不能在输出将成为top.php中的css的内容后使用header。您可以使用3个选项,或者使用元刷新重定向

echo '<meta http-equiv="refresh" content="0; URL=' . $url . '">';
0是站点刷新前应显示的延迟时间

您可以使用ob\u start&ob\u end\u clean

PHP:


为了停止代码的执行,必须使用exit或die after头。此外,在任何输出之前都必须执行代码。

Hi-Rocky其css位于top中。如果标头已发送,则使用标头进行预定向将不起作用,在调用标题之前,请确保您没有回显某个内容,即使是标题之间的空格?>编辑此帖子会使回显更加困难,因为?>您无法回显,您将不得不使用回显尼斯回复各位亲爱的,它使用的是java脚本..但为什么不使用标题“location:test.php”@PrabhasMandal,如果javascript被禁用,那么它将无法工作!!!很好,学到了一些新东西:不知道还有其他选择+1@sguetsch不客气:第三种选择-使用请参见第二个注意事项
<?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";
}

?>
header("Location: yourpage.php");
exit;