header()

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
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

header()

Post by Coco »

just a quick question.... if im using header() to redirect from a page that needs to update a table and then pass 2 strings to the redirect page, can i put html form fields in before the header when they are hidden type?

if not would i have to put the results in another file?
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Forms will not submit on a header call, furthermore outputing forms before call header will generate a fatal error. The common ways to pass data when using header are to either encode the parameters into the query string of the URL or to use session variables.

You may want to also consider writing a function to wrap around header() if you are using sessions as transparent sessions do not currently attach the SID to local URLs in headers if cookies are not used for propagation..
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

From the manual entry for header():
php docs wrote:Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
Hidden form fields are still HTML tags and therefore count as output. If you need to have these before the header() function is called look into output buffering.

Mac
User avatar
~J~R~R
Forum Newbie
Posts: 20
Joined: Wed Sep 18, 2002 12:19 pm
Location: Amsterdam, the Netherlanda

Post by ~J~R~R »

Using output buffering makes no sense. The output is buffered, but not not printed, because you use a header() before it, so the page is already redirected.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

look through it, it might have some POST header definitions...

other than that, you can try this:

1st) send it in get
2nd) grab the variables and cram them into a session
3rd) header the page to itself, without the get variables.
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post by Coco »

ok i started toying with sessions to get past this problem, now im finding that my redirect does nothing....

can header("Location: ") be used in frames?
and also does sending session variables count as sending content to the browser such as to break the header?
i dont even get a header error it just gives a blank page
and yes, im using a full address not relative
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post by Coco »

ho hum
:oops:
found my problem :cry:
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

What was your error? I ask simply so that anybody else who searches the forum and has the same problem doesn't have to ask the question again.

Mac
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post by Coco »

i had an error in my script which meant that i didnt even execute the header()

now you see why i was embarressed 8O
Post Reply