View Full Version : php browser control
TheSaint
02-16-2004, 07:58 PM
I am trying to use the header() function for browser control.
This is what I have:
header("Location: page.php");
I am getting this error
Warning: Cannot modify header information - headers already sent by....
There is not any HTML output before the php tags. I read that might be causing the problem, but I am still getting the same error. I also read that there are output control library functions that can help avoid this problem.
Any suggestions, either about which functions to try or what I may be doing wrong.
Thanks
Check the PHP header documentation (http://www.php.net/header) as well as ob_start() (http://www.php.net/manual/en/function.ob-start.php) .
Some browsers do not hadle the header function well so you may want to consider different ways of displaying alternate content.
Something like:<?PHP
if (somecondition) {
include 'somecontent.html';
} else {
include 'someothercontent.html';
}
?>
Viper007Bond
02-17-2004, 03:40 AM
If you do decide to use header(), it will need to be used when nothing has been outputted already, i.e. text, images and such.
Example:
<?php
echo "Some text.";
header("Location: page.php");
?>
That will not work.
TheSaint
02-17-2004, 10:23 AM
OK so if there is any ouput then I will get that error, it is not limited to HTML output? I am trying to write form elements into a db on that page and then direct it to another page. Would that be throwing the error?
Also I am having trouble with updating the db after a user has entered information.
$updateQuery = "UPDATE table SET"
"first_name =" $firstName ","
"last_name = " $lastName ","
"WHERE user = $user";
I have tried it with slashes and periods and am getting syntax errors. I understand the sql but am having trouble translating that into php.
thanks
Your query should be:$updateQuery = "UPDATE table SET
first_name = '$firstName',
last_name = '$lastName',
WHERE user = '$user'";
Did you look at the ob_start() function as I mentioned in my previous post? This buffers output until your script has finished sending the header info first.
TheSaint
02-17-2004, 12:01 PM
Thanks for all the help I got everything working users can now enter their info into the db and update it also. In case others are having the same problem:
One thing that it took me a while to figure out was that there was an extra comma after the last field to update just before the 'WHERE' line. Just make sure to omit that or it will give you syntax errors.
$updateQuery = "UPDATE table SET
first_name = '$firstName',
last_name = '$lastName'
WHERE user = '$user'";
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.