Jump to content

stupid question about Header


robert_gsfame

Recommended Posts

i got this code

 

<?php require_once('config.php');?>

<?php if(isset($_POST['login'])){

if(empty($_POST['username'])||(empty($_POST['password']))){header('location:failure.php');}}?>

 

when i run it, then this statement appeared

CANNOT MODIFY HEADER(HEADER ALREADY SENT

 

can anyone find out which part is wrong?

thx

Link to comment
https://forums.phpfreaks.com/topic/168827-stupid-question-about-header/
Share on other sites

this is what my config.php look like

 

<?php

$localhost='localhost';

$username='xxxxxx';

$password='XXXXX';

$database='YYYYYYY';

mysql_connect($localhost,$username,$password);

mysql_select_db($database);?>

 

which part is wrong, it seems i don't have any space wrongly placed

The whole error message states where the output is occurring that is preventing the headers from working.

 

Reading the error message would indicate where to look. The problem is either characters or content being output from the files or due to the Unicode/UTF-8 BOM characters that an editor places at the start of the file. The problem could be with either the main file or the file being included.

the second you break out of php and output markup OR whitespace headers are sent.

 

you can prevent this by coding so that all logic is executed/all processing done BEFORE you start building the page OR by using output buffering

 

buffering may not be the best option but if you have lots of legacy code it will solve it in the short term.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.