我的 php 标头标签不会重定向 [英] My php header tag will not redirect

查看:34
本文介绍了我的 php 标头标签不会重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试过进行研究,但看起来似乎并不成功.我确保在我的标题标签之前没有内容打印到屏幕上.

I've tried doing my research and it doesn't look like I'm coming up successful. I made sure there is no content being printed out to the screen before my header tags.

此页面从前一个登录页面的表单中获取信息,并使用该信息来确定用户应重定向到哪个页面.不幸的是,看起来我的任何标题标签都没有重定向到任何内容,它只是停留在这个 php 页面上.

This page is taking information given from the form in the previous login page and using that information to determine which page the user should be redirected to. Unfortunately, it doesn't look like any of my header tags are redirecting to anything, it just stays on this php page.

为了调试,我已经回显了每个场景(登录、退出、错误的密码)并且每个场景都有效,但显然当我回显时重定向不起作用.我只是想测试一下信息是否正确传输.

To debug, I have echo'd each scenario (logged in, out, wrong pw) and each scenario works, but obviously when I echo'd the redirect wouldn't work. I just wanted to test that the information was being transmitted correctly.

其他人能帮我看看局外人的看法吗?

Can anyone else help and give me an outsider's perspective?

<?php
session_start();
include('dbconnect.php');
$email = trim($_POST['email']);
$password = trim($_POST['password']);
$query = "SELECT password FROM artists WHERE email='$email'";
$passwordMatch = mysqli_query($db, $query);
$row = mysqli_fetch_array($passwordMatch);
if($row[0] == $password){
    $query = "SELECT active FROM artists WHERE email = '$email'";
    $active = mysqli_query($db, $query);
    $active = mysqli_fetch_array($active);
    $active = $active[0];
    if ( $active == 0 ){
        header('Location: validate.php');
    }
    else{
        header('Location: artistHome.php'); //redirect to user home page and update session
        $_SESSION['user']= $email;
        unset($_SESSION['error']);
    }
}
else{
    header("Location: login.php");
    $_SESSION['error']= 'Invalid Password';
}
?>

推荐答案

这里有大约数千个这样的帖子.去掉 php 结束标记 ?> 和空格、html、php 开始标记 <?php 之前的空行.还要检查之前是否没有输出:

There were about thousands of posts like this one over here.Get rid of php closing tag ?> and whitespaces, html, blank lines before php opening tag <?php. Also check if there is no output before :

header("Location:");

比如printvar_dumpecho等等.

还要检查您的 if 条件,也许您只是跳过它.

Also check your if condition, maybe you are just skipping it.

如果您includeinclude_oncerequire_oncerequire,请检查包含文件中的上述所有内容.

If you include,include_once,require_once or require check all the things above in the included files too.

缩小范围以更正查看您的 php error_log 并向我们提供错误描述.

To narrow a circle of the things to correct look into your php error_log and provide us with error description.

这篇关于我的 php 标头标签不会重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆