vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Headers already sent by . . .Snag with integration with Amazon Shop -- SOLVED (https://vborg.vbsupport.ru/showthread.php?t=80862)

kyouens 05-02-2005 03:04 AM

Headers already sent by . . .Snag with integration with Amazon Shop -- SOLVED
 
Hi everybody,

I have a quick question. I'm working on an integration of Ghostscripter's Amazon Store with my vBulletin installation, and I've come across a problem. I've got the script fairly well integrated into my site, with the header and footer "sandwiching" the Amazon Store code. Here's the code I add to the beginning of the Amazon Store php files to make most of it work:

PHP Code:

<?php
error_reporting
(E_ALL & ~E_NOTICE);
define('NO_REGISTER_GLOBALS'1);
define('THIS_SCRIPT''bookstore'); //Change to match file name
chdir('/var/www/html/vbulletin/');  //Change to server path of yoru forums
$globaltemplates = array(
    
'footer',
    
'header',
    
'navbar',
);
if (
$_REQUEST['page'])
{
    
$globaltemplates array_merge($globaltemplates);
}
require_once(
'./global.php');
globalize($_REQUEST, array('page' => STR,));

eval(
'$nakedheader = "' fetch_template('nakedheader') . '";');
eval(
'$footer = "' fetch_template('footer') . '";');
eval(
'$navbar = "' fetch_template('navbar') . '";');

$headinclude str_replace(array('"clientscript''url(images/gradients'), array("\"$vboptions[bburl]/clientscript""url($vboptions[bburl]/images/gradients"), $headinclude);
$footer str_replace('"cron.php'"\"$vboptions[bburl]/cron.php"$footer);

if (
$shownewpm AND $vboptions['showpm'])
{
    eval(
'$pmscript = "' fetch_template('pm_popup_script') . '";');
    
$footer .= str_replace('"private.php'"\"$vboptions[bburl]/private.php"$pmscript);
}
//-------- End call to VBulletin header and footer -------//
chdir("/var/www/html/amazon/");

After I do this, I have no problem with echoing my header and footer to the Amazon Store pages. The problem is when I try to access the cart.php to add items, etc. The urls when an item is to be added look like this:

HTML Code:

http://myserver.com/amazon/cart.php?cmd=add&asin=0345391802
When I try to do this, I get the following error, and no I don't have whitespaces before or after my php tags:
Quote:

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/amazon/cart.php:35) in /cart.php on line 116
I know that this error is occurring because global.php sends header / cookie information and the cart.php file also sends header information. I guess something must be getting printed or echoed in between. Here's an example of the code from cart.php that's altering the header (would post more but this code is proprietary):
PHP Code:

case'clear':
    unset(
$_SESSION['cart']['items']);
    
header("Location: cart.php");
    break;
case 
'remove':
    unset(
$_SESSION['cart']['items'][$_GET['asin']]);
    
header("Location: cart.php");
    break; 

Does anyone know of 1) a way to put all the output of global.php into a variable or something like that, then echo it in the cart.php file? 2) some other brilliant thing I haven't thought of yet?

I know people doing integrations of external scripts have come across this problem and I was wondering if anyone had a clue.

Thanks,
Kenny

Reeve of shinra 05-02-2005 04:10 AM

Try using this:
https://vborg.vbsupport.ru/showthrea...threadid=66084

kyouens 05-02-2005 09:23 PM

Quote:

Originally Posted by Reeve of shinra

Thanks for the link--that is a cool hack--but unfortunately it doesn't work for dynamic php pages, only for static ones. :( Anyone got any other ideas?

Guy G 05-02-2005 09:36 PM

That sometimes happens if you have a space between the ending for the page and the ending of the script.

delete all that is between the ?> and the end.

kyouens 05-02-2005 09:47 PM

Quote:

Originally Posted by Guy G
That sometimes happens if you have a space between the ending for the page and the ending of the script.

delete all that is between the ?> and the end.

There's not any space there in my file. I checked after I came across that as a solution in my first round of forum searching for an answer :) Thanks.

I was able to resolve this issue, and I think the solution I found could be useful for integration of other complex scripts that send their own cookies, change headers, etc.

What I did was this: Made a seperate php file called headerinclude.php like this:


ob_start();
--include global php
--output the header only
(This is shown in several other forum posts.)
$header=ob_get_contents();
ob_clean();


Then I included headerinclude.php and encompassed the rest of the contents of my external file (except the php tags, obviously) (in my case cart.php) in another set of output buffer.


-include headerinclude.php
ob_start();
--EXTERNAL PHP file goes here
(This is shown in several other forum posts.)
$content=ob_get_contents();
ob_clean();


Then I echo this:

echo $header;
echo $content;

and it works, with all cookies, etc. apparently intact, and without that header already sent error.


All times are GMT. The time now is 01:02 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03598 seconds
  • Memory Usage 1,752KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_html_printable
  • (2)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete