Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/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_Session_Authentication_Login - Fatal编程技术网

Php 表单登录错误

Php 表单登录错误,php,session,authentication,login,Php,Session,Authentication,Login,可能重复: 我的网站的登录表单有问题。在login.php表单的顶部,我有一个 <?php if (isset($_SESSION['username'])){ header("Location: http://myurl/"); die;}?> <?php require 'includes/dbconnect.php' ; ?> <?php require 'includes/header.php'; ?> header.php <?ph

可能重复:

我的网站的登录表单有问题。在
login.php
表单的顶部,我有一个

<?php 
if (isset($_SESSION['username'])){
header("Location: http://myurl/"); die;}?>
<?php require 'includes/dbconnect.php' ; 
?> 
<?php require 'includes/header.php';  ?>
header.php

<?php session_start(); ?>
更新2

<?php require 'includes/header.php';?>
<?php if (isset($_SESSION['username'])){
header("Location: http://myurl/"); die;}?>
<?php require 'includes/dbconnect.php' ; ?> 
指向
$username=trim($\u POST['username'])
as
输出从/path/to/file/header.php:11开始

更新

header.php

<?php session_start(); ?>
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="description" content="Your description goes here" />
<meta name="keywords" content="your,keywords,goes,here" />
<meta name="author" content="Your Name" />
<link rel='stylesheet' type='text/css' href='css/theme.css' />
<link rel='stylesheet' type='text/css' href='css/fullcalendar.css' />
<link rel='stylesheet' type='text/css' href='css/fullcalendar.print.css' media='print' />
<link rel="stylesheet" href="css/jquery.tagbox.css" />

如果header.php有session\u start()调用,则它必须位于文件的顶部。实际上,我希望您会收到“Headers ready sent”消息,因为在dbconnect include之后,代码中有一个换行符


当您使用session_start时,最好将它放在将要使用它的每个文件的顶部;这有助于确保在会话开始之前不会发送任何标题。

请尝试将其放在页面顶部:

<? ob_start(); ?>

然后在页面底部放置以下代码行:

<? ob_flush(); ?>


感谢您的回答:我已将标题移至页面顶部。但是仍然会出现相同的错误您可以用当前的代码更新您的问题吗?它是否仍然会给您相同的错误消息,或者行号是否已更改?当我在localhost中尝试时,它工作正常,但是如果您移动了header.php,它将不再位于第7行-是这样吗?那太令人困惑了。。。您可能已经在localhost上打开了输出缓冲,这也可能是一个解决方案:您的login.php文件的末尾或开头是否有空行/空格?
<?php session_start(); ?>
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="description" content="Your description goes here" />
<meta name="keywords" content="your,keywords,goes,here" />
<meta name="author" content="Your Name" />
<link rel='stylesheet' type='text/css' href='css/theme.css' />
<link rel='stylesheet' type='text/css' href='css/fullcalendar.css' />
<link rel='stylesheet' type='text/css' href='css/fullcalendar.print.css' media='print' />
<link rel="stylesheet" href="css/jquery.tagbox.css" />
<? ob_start(); ?>
<? ob_flush(); ?>