At 2003-06-02 01:49 +0500, Haseeb Iqbal wrote:
>when ever i set a cookie it didn't get set even i refresh the page (with php header 
>function) but then i echo something on the page and then use HTML meta refresh the 
>cookie becomes availble on the next page.
>what is it that i am missing here.

I'm not sure what you're trying to say, but please be aware that
you can only set cookies and output header() info before any
normal output has taken place. If for example an include file
has an empty line after it's closing '?>'-line it will output
an empty line in HTML and no more cookies and header info
can be send (in the main file).

Check out the ob_start() (output-buffer start) function
in the manual and also the sections about cookies and
about the header() function. It is all being explained
somewhere but it may be hard to find and piece together.
It took me quite a while in an older version of the
manual. (But currently Chapter 17 is very clear about it.)

To make a fail-safe system, try this in your main .php
file:

<?php
//make sure the previous line is the first line in the file
ob_start();

include "whatever.php";

In the include file and the rest of the file you can use
header() and setcookie() etc. as much as you like,
as long as you don't flush the output buffer.

Beware however that debugging scripts like these might
get a lot tougher since all output is halted until the
script ends and if something goes wrong it may not
output it's data at all.

Greetings,
Jaap


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

Reply via email to