473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

problem using ob_start(), ob_end_clean() and header() combination

I traced the problem to what I believe is when I use the included
content library script into the viewinterns.php page. This script
will repeatedly instantiate a DateGroupHTMLGenerator class because I
have to constantly produce these HTML form element fields with
different names throughout my page. Here is the code I use to
reproduce it everytime:

<?php

$gradArray = array();
foreach(array('graduation_month', '', 'graduation_year') as $key =>
$val)
$gradArray = $gradArray + array($val => $$val);
array_push($gradArray, 2); // ADD TEXT FIELD SIZE
$dateGroup =& new DateGroupHTMLGenerator($gradArray, 1, 0, 1);
echo $dateGroup->getMonthDropdown() . $dateGroup->getDayDropdown()
.. $dateGroup->getYearText();
?>

This is one of the dategroup HTML content snippets throughout the
library. There are several of them since the form is rather large and
requires an enormous amount of data including several month/day/year
groupings, all having different names (see the foreach() loop for more
clarification on naming convention, etc.).

At the end of this library script I do the following:

<? $dateGroup = null; ?>

I zero-out the object. Upon review, however, I am convinced that
somehow a latent object or a latent buffer is still floating around.
Here is the code to DateGroupHTMLGenerator constructor method:

// CONSTRUCTOR
function DateGroupHTMLGenerator($classPropertyArray, $hasMonth = 1,
$hasDay = 1, $hasYear = 1) {
global $REQUEST_URI;

foreach(array('month', 'day', 'year') as $key => $val) $this->{'has'
.. ucfirst($val)} = ${'has' . ucfirst($val)};

$this->propertyArray = $classPropertyArray;

// CONVERT THE INPUT PARAMETER ARRAY INTO A 2-DIM ENUMERATIVE ARRAY
TO PRESERVE KEYS AND VALS AND HAVE ENUMERATION FOR SWITCH
$enumKeyValArray = array();
foreach($this->propertyArray as $key => $val)
array_push($enumKeyValArray, array($key, $val));

// GET THE VALUE OF THE LAST ELEMENT OF THE INPUT PARAMETER ARRAY
WHICH WILL BE THE TEXT FIELD LENGTH
$textFieldLengthArray =
array_values(array_reverse($this->propertyArray));
$textFieldLength = $textFieldLengthArray[0];

$this->htmlArray = array();

$monthArray = array('01' => 'January',
'02' => 'February',
'03' => 'March',
'04' => 'April',
'05' => 'May',
'06' => 'June',
'07' => 'July',
'08' => 'August',
'09' => 'September',
'10' => 'October',
'11' => 'November',
'12' => 'December'
);
for ($i = 0; $i < sizeof($enumKeyValArray); $i++) {
$html = '';
switch ($i) {
case '2': // TEXT FIELD SLOT IN INPUT ARRAY PARAMETER
if ($this->hasYear) {
if ($textFieldLength == 2) $html = '20';
$html .= '<input name="' . $enumKeyValArray[$i][0] . '"
value="' . str_replace('"', '&quot;', $enumKeyValArray[$i][1]) . '"
size="' . $textFieldLength . '" maxlength="' . ($textFieldLength + 1)
.. '">';
}
break;

case '3': // SIZE OF TEXT FIELD - NOTHING NEEDS TO BE DONE
// DO NOTHING
break;

case '0': // MONTH DROPDOWN
if ($this->hasMonth) {
$html = '<select name="' . $enumKeyValArray[$i][0] . '">';
foreach($monthArray as $innerKey => $innerVal) {
ob_start();
preSelect($enumKeyValArray[$i][1], $innerKey);
$preSelectText = ob_get_contents();
ob_end_clean();
$html .= '<option value="' . $innerKey . '" ' . $preSelectText
.. '>' . $innerKey . ' - ' . $innerVal . '</option>';
}
$html .= '</select>';
}
break;

case '1': // DAY DROPDOWN
if ($this->hasDay) {
$html = '<select name="' . $enumKeyValArray[$i][0] . '">';
for ($j = 1; $j <= 31; $j++) {
$myDay = ($j < 10) ? '0' . $j : $j;
ob_start();
preSelect($enumKeyValArray[$i][1], $myDay);
$preSelectText = ob_get_contents();
ob_end_clean();
$html .= '<option value="' . $myDay . '" ' . $preSelectText . '>'
.. $myDay . '</option>';
}
$html .= '</select>';
}
break;

default: // THIS WILL BE EXPANDED FOR FUTURE IMPLEMENTATION OF
DATEGROUP, FOR NOW IF ANYTHING ELSE IS FOUND DO NOTHING
// DO NOTHING
break;
}

$this->htmlArray[$i] = $html;
}

}

I have certain fields surrounded by ob_start() and ob_end_clean()
because the function those commands surround does an 'echo'
(required). So to prevent it from going to stdout that is why I have
ob_start() and ob_end_clean() around them. However, when the user
submits the form generated by the library using this class object, it
will instantiate a saveData class object that saves everything (no
headers produced mind you) and then does a redirect header() command.
Whenever anyone does that they get this specific warning:

Warning: Cannot add header information - headers already sent by
(output started at /var/www/html/development/phillip/libdev/html.inc:160)
in /var/www/html/development/phillip/admin/viewinterns.php on line 659

Mind you, the saveData class in viewinterns.php does NOT instantiate
anything in html.inc, much less a DateGroupHTMLGenerator class
instance, which is exactly what this warning is pointing to (the line
160 in html.inc is the end of the entire html.inc, classes and all).

I'm totally stumped. If I replace "header()" with client-side
redirection it works but is EXTREMELY slow (avg download time 20 - 30
seconds per page), so it's not an option. I do not know what to do at
this point so I really need help.

Thanks
Phil
Jul 17 '05 #1
0 4524

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Phil Powell | last post by:
Based upon the following articles: http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_20708448.html http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_20717295.html...
2
by: R. Gregg Reed | last post by:
I'm trying to intergrate a cgi affiliate tracking system into a php website. When someone pays using PayPal it's supposed to direct them to one page if the payment is a success or another if...
0
by: Phil Powell | last post by:
What is the most standardized method of utilizing the CURL functions in PHP (version 4.3.2) to be able to retrieve the contents of a remote URL that happens to be dependent upon $_SESSION for its...
2
by: skadmin | last post by:
I have a VERY frustrating script problem I hope some one can help me with. I am using part of the following PHP download script to allow users to download files from my website: <?php $file =...
3
by: Martin Braun | last post by:
hi folks, this piece of code should not display anything: ob_start(); print_r($users); ob_end_clean; well, for me it does - does anyone know why? in fact, it looks like the
6
by: windandwaves | last post by:
Hi Folk Some of my clients asked me to create "fancy emails" for them (aka html formatted emails). I know how to make a nice html document, but I had trouble creating a simple way to provide...
0
by: totalstranger | last post by:
I'm hoping someone can help figure out how to stop a message that appears to be generated by my web host when sending to an non-resolvable email address that is supported by my web host. Things...
3
by: anis2007 | last post by:
Hi, following code run our server but this is not run client server:- index code is: PUT YOUR CODE BETWEEN code OR php TAGS!! It is absolutely unreadeable! <?php ob_start(); session_start();...
5
by: yhd1997 | last post by:
Can you please help me to solve this cache problem? I have a php script that can save the content to a cache folder. But I can not get it to work to display the cached page. The script will...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.