Jump to content


Photo

Headers being sent twice (Solved- thanks for the help)


  • Please log in to reply
6 replies to this topic

#1 PaulD

PaulD

    Likes Etomite Forums!

  • Developers
  • PipPip
  • 413 posts

Posted 17 March 2010 - 12:12 PM

Hi,

I have been reading my wordpress database using this snippet, and some strange behaviour is occurring that I cant understand.

$wordpress = '';

// set the options for the query
$host="localhost"; 
$user="username";
$pass="password";
$dbase="`database name`";
$fields="*";
$from="wp_posts";
$where="post_status='publish' AND post_type='post'"; 
$sort="post_date";
$dir="DESC";
$limit=1;
$push=true;

// run the query
$results = $etomite->getExtTableRows($host,$user,$pass,$dbase,$fields,$from,$where,$sort,$dir,$limit,$push);

if($results)
  {
         foreach ($results as $post)
        {
                $wordpress .= '<h3><a href="'.$post['guid'].'" title="'.$post['post_title'].'">'.$post['post_title'].'</a></h3>';
                $wordpress .= '<p>'.$post['post_excerpt'].'<br /><small>Posted '.$post['post_date'].'. Comments '.$post['comment_count'].'. <a href="'.$post['guid'].'" title="'.$post['post_title'].'">Read More</a></small></p>';
         }
  }
else
  {
  $wordpress .= 'No posts found';
  }        

return $wordpress;


In the manager window, the page is fine and everything is working, but when I go to the live page, there is a header being attached on the bottom of the page and an error message.

The error message is

« Error »
Etomite encountered the following error while attempting to parse the requested resource:
« PHP Parse Error »

PHP error debug
Error: Cannot modify header information - headers already sent by (output started at (removed for security)/index.php:2070)
Error type/ Nr.: Warning - 2
File: /(removed for security)/index.php
Line: 324
Line 324 source: header('Content-Type: '.$type.'; charset='.$this->config['etomite_charset']);

Parser timing
MySQL: 0.0050 s s (3 Requests)
PHP: 0.5344 s s
Total: 0.5394 s s


It looks like a new header is being pasted on the bottom of the code. I have a fresh install of 1.1 (Prelude) and when I remove the snippet the page works fine and the error dissappears.

Thank you in advance for any ideas to solve this,

Paul.

EDIT: Changed title to solved so people don't think there is anything wrong with the function or etomite.

Edited by PaulD, 18 March 2010 - 09:31 PM.


#2 Ralph

Ralph

    Loves Etomite Forums!

  • Admin
  • 6,539 posts

Posted 17 March 2010 - 12:58 PM

While remote, is it possible that the data you are pulling from WordPress contains headers...???

#3 Cris D.

Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts

Posted 17 March 2010 - 03:38 PM

In addition, I'd make sure that there are no other snippets in the template that may be trying to re-parse the page like getSideBar. The managers' dumpSnippets function is a good tool to identify issues like this.

#4 PaulD

PaulD

    Likes Etomite Forums!

  • Developers
  • PipPip
  • 413 posts

Posted 17 March 2010 - 11:33 PM

Thanks for the suggestions although am still stuck. I was using some complicated docchunks, as well as the twittersuite and (it suprised me how many) lots of little snippets in the template as well (but not getsidebar). So I created a blank template with just html, head and body tags and the content call. I also checked the contents of the database and there is only the expected text and data in there.

Using the wordpress snippet on that blank template I still get an error (although a different one now). However, within the manager the page is exactly as expected. Another strange thing is that when I first visited the page it worked. Then when I navigated away and back, the error appeared and has remained since. The wordpress snippet seems to be working as the blog post and post info appears fine. Then the strange header bit comes.

Here is the page contents with the blank template:

e-Gravity chooses Wordpress for it's Blog.

Hello world. We have chosen Wordpress.

Posted 2010-03-15 23:31:08. Comments 1. Read More
e-Gravity
« Error »
Etomite encountered the following error while attempting to parse the requested resource:
« Execution of a query to the database failed »
      SQL: INSERT INTO `(database name)`.eto_log_access(visitor, document, timestamp, hour, weekday, referer, entry) VALUES('5821213', '9', '1268865184', '22', '3', '1654365787', '0')
      [Copy SQL to ClipBoard]
 
Parser timing
  MySQL: 	0.0043 s s	(3 Requests)
  PHP: 	0.0096 s s	 
  Total: 	0.0139 s s

You can see it here http://www.e-gravity.co.uk/test2.html
The blog contents are coming from here http://www.e-gravity.co.uk/blog/

The bit being added into the html after the templates </html> is

<html><head><title>Etomite 1.1 Prelude</title>
    <style>TD, BODY { font-size: 11px; font-family:verdana; }</style>
    <script type='text/javascript'>
      function copyToClip()
      {
        holdtext.innerText = sqlHolder.innerText;
        Copied = holdtext.createTextRange();
        Copied.execCommand('Copy');
      }
    </script>
    </head><body>
    <h2><a href='/index.php' title='e-Gravity'>e-Gravity</a></h2>

I have no idea where that is coming from at all.

I have never seen a page work in the manager window but not on the live site. When I comment out the function call the script behaves exactly as expected, defaulting to the 'no posts' message. But then, adding the function call again, the error reappears, although the function call itself seems to work normally in that the blog post is retrieved and all the data is displayed.

I can only think of two things. That there might be something wrong with the getExtTableRows function , or that there might be something wrong with my install, but I cant see a reinstall changing anything because everything else is working fine.

Do you think I should try a reinstall? Or could there be something up with the getExtTableRows function? In truth, I can't see either being the real problem. I have tried to find out if there is something my host doesn't like, but if it was the host then the error would be a 'failed to connect' error, not the strange resending of the header. As far as I can see, I am not doing anything that could cause a re-parse problem.

Any more ideas would be warmly welcomed. This is a new site so a reinstall isn't really a problem, although I won't do that until tomorrow night now.

Thanks again for your help,

Paul.

#5 Ralph

Ralph

    Loves Etomite Forums!

  • Admin
  • 6,539 posts

Posted 18 March 2010 - 12:09 AM

I'm going out on a limb here and guessing that this is an older site that hasn't been properly upgraded... Notice the negative number... That's what is causing the DB error...

SQL: INSERT INTO `web132-pauld`.eto_log_access(visitor,
document, timestamp, hour, weekday, referer, entry) VALUES('1333606933',
'9', '1268870694', '0', '4', '-1410195605', '1')


You can run the DB upgrade patch included in the Etomite Prelude v1.x Installer/Upgrader at any time without causing DB problems...

The Javascript part, along with the extra HTML, is being added by the Etomite Manager along with the error information...

#6 Cris D.

Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts

Posted 18 March 2010 - 09:52 AM

I'd also make sure the page and snippets are not cached as well until you get it working.

#7 PaulD

PaulD

    Likes Etomite Forums!

  • Developers
  • PipPip
  • 413 posts

Posted 18 March 2010 - 09:28 PM

Hi Ralph and Cris,

Thank you for the suggestions about this. I never worked out the cause of the problem, but have solved it now. The site was actually completely fresh and up to date. based on the current download file, and I had already completely uncached everything including snippet calls and page content. The error was weird. So weird that I finally bit the bullet and tried a complete reinstall from another fresh download and a new database.

Having done that, and with the default template, added the wordpress snippet and a call from the homepage and it all worked fine. I am really pleased that it is now working, but a bit frustrated about what I could have done to break the previous install. I can only guess that some file got corrupted along the way, probably on the upload. The only difference this time is that I used the full install, and not the lite version. However I bet it would have worked still even if I did use the lite version.

Thanks again for the help and suggestions. It is very much appreciated.

Paul




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users