Hi everybody,
I have a problem with hearder function and i can't figure it out. I need to redirect(by code, not links or buttons) the user to another page so i put the line
header("Location: pagename.php").
It doesn't work, i get a warning like "cannot modify header information" and i dont know how else i can do it without header or what to do to not receive that warning. Please give me a hint.
Thanks.
problems with header function
You need to call header() before you output anything. By output, this could also just be <html> tags.
Also check you script for other syntax errors, Cause php outputs the error when it occurs and with that some headers and when you try to send your header, it would produce that error
Thank. But i need to call header function when i need to call it. Or should i call it first header() and then to use it with location? I dont know, i'm idiot, explain me, open my eyes.
header() is exactly that: headers. You can't just call it at any old time. If you need something to happen for you, you should look at javascript redirection.
There is of course no point sending any output to the browser anyway if you're going to be sending a Location: header, because the browser will ignore the output and follow the redirect. So if the script is going to redirect the browser there is no reason to send any output first.
Thanks guys, header function is not the right option for what i want meaning to load another page if some conditions are respected. Look like i need javascript. Thanks again.