Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.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_Header - Fatal编程技术网

Php 检查会话时,使用标头()的重定向无法正常工作

Php 检查会话时,使用标头()的重定向无法正常工作,php,header,Php,Header,我的头有问题 我正在开发登录功能。。。在那 1) 如果用户使用其凭据登录 2) 之后,用户尝试打开新选项卡并键入LoginViewController.php 3) 在这里,我需要将用户重定向到以前登录的页面..基于seesion active 4) 但是标题没有重定向到loggedin.php页面。。并显示一些空白页 Here is the LoginViewController.php <?php session_start(); include('GenericClasse

我的头有问题

我正在开发登录功能。。。在那

1) 如果用户使用其凭据登录

2) 之后,用户尝试打开新选项卡并键入LoginViewController.php

3) 在这里,我需要将用户重定向到以前登录的页面..基于seesion active

4) 但是标题没有重定向到loggedin.php页面。。并显示一些空白页

 Here is the LoginViewController.php

 <?php
 session_start();
 include('GenericClasses/GenericCollectionClass.php');
 include('Models/UsersModel.php');
 include('DataObjects/Users.php');
 include('DatabaseAccess/DBHandler.php');

     if(!empty($_SESSION['user']))// Here checking session is empty or not
        {
            header("Location : loggedin.php");// Here it is not redirecting properly
            die();
        }
        else 
         {       

         }?>
这是LoginViewController.php
这里是loggin.php

<?php
  session_start();
  header("Cache-Control: private, must-revalidate, max-age=0");
  header("Pragma: no-cache");
  header("Expires: Fri, 4 Jun 2010 12:00:00 GMT");
  include('GenericClasses/GenericCollectionClass.php');
  include('Models/UsersModel.php');
  include('DataObjects/Users.php');
  include('DatabaseAccess/DBHandler.php');

      if(!isset($_SESSION['user']))
         {
           header('Location: LoginViewController.php');
           exit();
          }
          echo '<div style="background:white; text-align:right"> Login  as:'.$_SESSION['user'].'<a href="LogoutViewController.php" style="text-align:right">Logout</a></div>';
         ?>


Any suggestions are acceptable... 

任何建议都可以接受。。。

将会话_start()放在顶部。它应该位于第一行的第一位,并从代码中删除不必要的空间

将会话_start()放在顶部。它应该位于第一行的第一位,并从代码中删除不必要的空间

会话启动()应该是第一行。此外,在输出任何内容后,您也不能执行重定向,这包括所包含文件的任何尾随空间。

session\u start()应该是第一行。此外,在输出任何内容后,您也不能进行重定向,这包括所包含文件中的任何尾随空格。

没有阅读代码,但乍一看您的问题,我可以向您建议三件事


  • session\u start()
    应该是
    之后的第一行。我没有仔细阅读代码,但乍一看你的问题,我可以向你建议三件事


  • session\u start()
    应该是
    正确格式化代码后的第一行
    
    Remember that header() must be called before any actual output is sent, 
    either by normal HTML tags, blank lines in a file, or from PHP.