RE: [PHP] Making your include files invisible (header() in if loop)

2002-01-31 Thread Peter Brown

I don't know if this is related but header() must be called before any
actual output is sent.

One way to resolve this is to use the ob_start() tag at the start of the
code, this turns output buffering on.

Mind you I am no expert and stand ready to be corected and berated.

Peter


I wanted to hide the existance of my include files by making them
'invisible': give a 404 error when requested. This worked, but the files
that were including were obviously 404ing too. So I decided to use
$PHP_SELF and check whether the script's PHP_SELF was it's filename,
which would mean that it was being accessed directly, as opposed to
being included. I tried this code:



(include.php)



at the top of the include files, but it wasn't working. Change the
header() to an echo and test it. It echoed. So it's a problem with the
header(). I tried this:





and it worked perfectly. Can header() not be in an if loop or something
like that?



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED] To
contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Problem...header already sent by

2002-02-04 Thread Peter Brown

If you include ob_start() at the beginning of the code this will turn
output buffering on and hence enable you to send the header() tag at any
line in the code.

Peter

-Original Message-
From: Ryan F. Bayhonan [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, 5 February 2002 5:54 PM
To: Peter; [EMAIL PROTECTED]
Subject: Re: [PHP] Problem...header already sent by


Hello Peter. Good Day.

Omitting  does not solve the problem. I've experience this
problem also before. I found out that the once causing the problem is
when any data that has been sent to the client. I have listed some
example below.

Examples: All of these will cause a warning when header is called.

1. Since the tag  will be interpreted by the client browser first
before the  tags, data has been sent to the client, telling
the client that an html file is being rendered. So when the browser
interprets the header function, a warning will be issued.




2. This will also cause an error. Remember that a call to an echo or
print function will send data (the parameters of the function) to the
client. So when the header is interpreted, a warning will be issued.



Hope this is clear to you now. When a data has been sent already to the
client, a call to a header will fail. The best thing you must do is to
put the logic/check part on the first line of the file (See below). In
the example below, I check first is the a user is valid by calling the
the function verify_user( params... ) before any other html tags be
rendered. So when the user is not valid it will redirect an error page,
if it is valid, the Welcome to page will be printed.




Welcome to the page.



Hope this help you more.

Until then...

Ryan F. Bayhonan

- Original Message -
From: "Peter" <[EMAIL PROTECTED]>
To: "Ryan F. Bayhonan" <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Tuesday, February 05, 2002 2:14 PM
Subject: Re: [PHP] Problem...header already sent by


> Hi Ryan,
>   I tried and took the  tags out and I still get the same

> messaage.  Why?
>
> Thanks,
> Peter
>
>
> > Hello Peter.
> >
> > I discribe my reply below:
> >
> > > **
> > > Warning: Cannot add header information - headers already sent by
(output
> > > started at C:\apache\htdocs\proj\sports\phps\verify.php:2) in 
> > > C:\apache\htdocs\proj\sports\phps\verify.php on line 26
> > > ***
> >
> > This warning message appear when the server already send data to the
> client.
> >
> > > 1. 
> > > 2.  > > 
> > >
> > >
> > >  23.   if (!$auth) {
> > >  24.  header("www-Authenticate: Basic realm='Private'");
> > >  25.  header("HTTP/1.0 401 Unauthrized");
> > > ...
> > > ?>
> > > 
> >
> > In the above code, the  tag has been sent to the client
> browser
> > already, thus when calling header function it would cause a warning
> telling
> > you that data has been rendered already.
> >
> > Hope this help.
> >
> > Ryan
> >
> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: Cannot add header information...

2001-11-22 Thread Peter Brown

If you add ob_start(); at the start of your code, then you will be able to
set Headers anywhere in your page.

Peter


> Per Waagen wrote:
>
> > Warning: Cannot add header information - headers already sent by (output
> > started at /home/p/pe/perphp/public_html/login.php:4) in
> > /home/p/pe/perphp/public_html/login.php on line 44
> --
> Avi Schwartz
> [EMAIL PROTECTED]
>
> "I have to share the credit. I invented it, but Bill made it
> famous." - IBM engineer Dave Bradley describing the
> control-alt-delete reboot sequence




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]