Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

? about page loading

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

? about page loading

Postby jmoney » Mon Apr 07, 2003 2:21 pm

kj
Last edited by jmoney on Mon Apr 07, 2003 5:59 pm, edited 2 times in total.
jmoney
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Apr 07, 2003 2:18 pm

Postby paintcheck200 » Mon Apr 07, 2003 2:52 pm

I have the same type of problem :?

I'm trying to use header in a function when it is called

Code: Select all
function accessGranted( $name ){
            header( 'Location: logged.php');
            exit();   
}


but I get this error,
Code: Select all
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/lab6/login.php:8) in /var/www/html/lab6/login.php on line 101


I've found a lot online about this error, and even found something that said if you use any html at al it won't work, so I took all the html out.. but now, I still get this error[/code]
paintcheck200
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Apr 07, 2003 2:47 pm

Postby jmoney » Mon Apr 07, 2003 3:00 pm

exactly.. Im gettin same problem.. thats why im wondering if HEADER is the wrong thing to use?
jmoney
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Apr 07, 2003 2:18 pm

Postby pecoes » Mon Apr 07, 2003 11:45 pm

Well, the headers are part of the negotiations between server and browser, so you have to put them before any html (even the doctype) and before any echo or other output.
Your error message clearly states "output already started".

regards, Pecoes
pecoes
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon Apr 07, 2003 11:17 pm

Postby pecoes » Mon Apr 07, 2003 11:52 pm

I forgot: If you have to print the redirect somewhere "in the middle" of the page use this:

Code: Select all
<SCRIPT LANGUAGE="JavaScript">
   <!--
      location.replace("<?=$other_page?>");
   //-->
</SCRIPT>
<NOSCRIPT>
   <META HTTP-EQUIV="Refresh" CONTENT="<?=$other_page?>">
</NOSCRIPT>
pecoes
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon Apr 07, 2003 11:17 pm

Postby paintcheck200 » Tue Apr 08, 2003 12:55 pm

Thx Peocos, :D
I took out the DocType and it works, If I put the doctype at end of the page so that I can try to validate it, should that still work?
paintcheck200
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Apr 07, 2003 2:47 pm

Check whitespace

Postby andrewdavey » Wed Apr 09, 2003 2:28 am

A common problem I find when adding headers is if there is a whitespace before the starting PHP tag.
For example:
Code: Select all
<?php

header('Location: http://www.php.net/');
?>

This whitespace is counts as an output and is sent to the browser, thus generating the header error message.
andrewdavey
New php-forum User
New php-forum User
 
Posts: 16
Joined: Wed Feb 12, 2003 5:27 am
Location: Cornwall, England


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron