Page 1 of 2
header() prolems
Posted: Wed Aug 21, 2002 3:04 pm
by matthiasone
I am trying to redirect to a clean form after a data insert in te mySQL...but when I run the script.......the insert works but I get a blank page.
Code: Select all
function do_pages($area, $page="default", $view="", $user="", $id="", $eid="", $form_vars="")
{
do_html_header();
load_menu($user);
if ($page == "default")
load_default();
elseif ($page == "userform")
form_user($user, $id);
elseif ($page == "cal")
{
if($view == "yr")
form_cal_yr($id, $user);
elseif($view == "mth")
form_cal_mth($id, $user);
elseif($view == "day")
form_cal_day($id, $user, $eid);
elseif($view == "new")
{
db_cal_entry($form_vars, $user);
$tdate = date("Y-n-j", strtotime($form_varsї"edate"]));
header("Location: staffpage.php?area=form&page=cal&view=day&id=".$tdate."&user=".$user);
}
elseif($view == "update")
{
db_cal_update($form_vars, $user);
$tdate = date("Y-n-j", strtotime($form_varsї"edate"]));
header("Location: staffpage.php?area=form&page=cal&view=day&id=".$tdate."&user=".$user);
}
}
do_html_footer();
}
Thanks
Posted: Wed Aug 21, 2002 3:09 pm
by nielsene
This may be a quick fix....
From the php manual
Note: HTTP/1.1 requires an absolute URI as argument to Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself:
Code: Select all
header("Location: http://".$_SERVERї'HTTP_HOST']
.dirname($_SERVERї'PHP_SELF'])
."/".$relative_url);
Posted: Wed Aug 21, 2002 3:23 pm
by matthiasone
that didn't work. But thanks for the suggestion.
Posted: Wed Aug 21, 2002 3:40 pm
by nielsene
Have you examined the url that the header is generating? Does it have all the name=value pairs you expected? Is it losing characters (do any fields need to be urlencoded?)? Have you confirmed that the variables are set properly in the _GET array? (You'll need to view the edit page, then update your source to print our the get array, save the source, then submit in order to avoid the can't send headers error message)
For instance, I can tell that if either page or view get corrupted(or aren't being set) you'll only output a header/footer/menu without content.
Posted: Wed Aug 21, 2002 4:11 pm
by volka
have you checked your system/error-log for something like
'Warning: Cannot add header information - headers already sent by (output started at file.php:23)'
if this happens read
this topic
Posted: Wed Aug 21, 2002 4:18 pm
by matthiasone
Vodka - yes, I have check the error log........not entry for a header.
nielsene - the generated url looks correct. but like you said I get a menu and head and footer but no content.
Not exactly sure I fully understand urlencoding...
Posted: Wed Aug 21, 2002 10:53 pm
by nielsene
The next thing I would try would be to add elses after both your if-elseif trees, with a simple echo "I'm here"; type line, just to see which variable is causing the problems. This won't fix anything, but it might help localize the problem.
Posted: Thu Aug 22, 2002 9:32 am
by matthiasone
Well I put echos in the first if to ehco the url and all the variable echoed out correctly.

Posted: Thu Aug 22, 2002 9:38 am
by nielsene
OK the next thing to try is:
Code: Select all
// snip
elseif($view == "day")
{
echo "I should be here, $id, $user, $eid";
form_cal_day($id, $user, $eid);
}
// snip
If you get the new message after the redirect then you know that something is wrong in form_cal_day and not in the code you showed us.
Posted: Thu Aug 22, 2002 9:52 am
by matthiasone
Ok here is the current snippet of code
Code: Select all
elseif($view == "new")
{
db_cal_entry($form_vars, $user);
$tdate = date("Y-n-j", strtotime($form_varsї"edate"]));
$relative_url = "staffpage.php?area=form&page=cal&view=day&id=".$tdate."&user=".$user;
echo $relative_url;
echo "Location: http://".$_SERVERї'HTTP_HOST']
.dirname($_SERVERї'PHP_SELF'])
."/".$relative_url;
header("Location: http://".$_SERVERї'HTTP_HOST']
.dirname($_SERVERї'PHP_SELF'])
."/".$relative_url);
}
elseif($view == "update")
{
db_cal_update($form_vars, $user);
$tdate = date("Y-n-j", strtotime($form_varsї"edate"]));
header("Location: staffpage.php?area=form&page=cal&view=day&id=".$tdate."&user=".$user);
}
When run this the is the resulting echos:
Location:
http://www.lufkin.org/staffpages/staffp ... -22&user=1
Posted: Thu Aug 22, 2002 10:08 am
by nielsene
OK, just looked at it and tried adding an event (I hope that was alright). And yes, the URL looks fine. However there definately should have been an error message. Double check the logs for the "Cannot send headers" message. I know you said it wasn't there before when volka asked. If its not there now, ether PHP is dropping all errors without telling/logging or you're looking in the wrong place. If you find them in a new place and older ones are also there then this is the common problem and can be fixed by reading the sticky announcements at the top of this forum.
Posted: Thu Aug 22, 2002 10:13 am
by matthiasone
Well now there is an error "Cannot send headers" in the logs. How do I go about fixing that?
Posted: Thu Aug 22, 2002 10:14 am
by nielsene
Take out the echo debug code and check if its still there.
Posted: Thu Aug 22, 2002 11:18 am
by volka
you may also turn on output_buffering in php.ini
but think of it as quick&dirty - it's always better to avoid it
Posted: Thu Aug 22, 2002 11:21 am
by matthiasone
Well I still get the same message
[Thu Aug 22 11:17:51 2002] [error] PHP Warning: Cannot add header information - headers already sent by (output started at /usr/home/faog/staffpages/staffpage_fns.php:133) in /usr/home/faog/staffpages/staffpage_fns.php on line 54