*solved* troubles using header functions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pedrotuga
Forum Contributor
Posts: 249
Joined: Tue Dec 13, 2005 11:08 pm

*solved* troubles using header functions

Post by pedrotuga »

I get this error:

Code: Select all

Warning: Cannot modify header information - headers already sent by (output started at /var/www/2006.04.18/ligabd.php:12) in /var/www/2006.04.18/login.php on line 30
on the line i use:

Code: Select all

header(location:xpto.php);
the ligabd only contains this:

Code: Select all

<?php

$dbname = "dbname";
$dbuser = "username";
$host = "myserver.com";
$password = "userpass";

mysql_connect($host, $dbuser, $password);
mysql_select_db($dbname);

?>
why da heck doesnt it redirect to xpto.php?
Last edited by pedrotuga on Tue Apr 18, 2006 10:48 am, edited 1 time in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Where's line 30 and do you know you haven't enclosed the string in header() inside quotes? (Might generate a notice).

EDIT | Look at line 12 of that other file too. I bet there's whitespace after the closing <?php tag.
User avatar
pedrotuga
Forum Contributor
Posts: 249
Joined: Tue Dec 13, 2005 11:08 pm

Post by pedrotuga »

line 30 contains this

Code: Select all

header("location: xpto.php");
byuseing include am i sending any header to the output? if so how can i use a redirect after an include?
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

Post by rubberjohn »

if there are any spaces before and after the php tags it will trigger an error like that and you cant have any output (echo/ print_r) before the header redirect line

rj
User avatar
pedrotuga
Forum Contributor
Posts: 249
Joined: Tue Dec 13, 2005 11:08 pm

Post by pedrotuga »

rubberjohn wrote:if there are any spaces before and after the php tags it will trigger an error like that and you cant have any output (echo/ print_r) before the header redirect line

rj

damn... i didnt know PHP had this strict rules... well.. i gess it should be due to spaces somwhere.

BTW... sorry this being a stupid question... but... allways beter to ask..

does an echo inside an IF which condition is not satisfied generates one of those errors? or should i only be carefull about echos that are runned successfully?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Only if it is sent succesfully.

Code: Select all

//    this will work
$x = 2;

if($x == 1){
    echo 'that';
}

header("Location: xxx.php");

//    this will not work
$x = 2;

if($x == 2){
     echo 'that';
}

header("Location: xxx.php");
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
pedrotuga
Forum Contributor
Posts: 249
Joined: Tue Dec 13, 2005 11:08 pm

Post by pedrotuga »

thank you all!

working... i pop up within a while with some other questions ;)..lol.. just hope not so soon
Post Reply