Jump to content

PHP script in body of HTML?


AdamAsh

Recommended Posts

Hey, I am now to this forum, and very new to the whole web design/PHP so please bear with me. I have read the topic around header errors but still do not understand how to get around this for my problem. I will do my best to explain.

 

I downloaded a free comment script for my (new) site - I have tried to integrate it and get the all too common message:

 

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /var/www/vhosts/djadamash.com/httpdocs/contact_me1.php:6) in /var/www/vhosts/djadamash.com/httpdocs/comments/include/session.class.inc.php on line 69

 

Now I have read about checking for white spaces etc and don't think that is my problem, what my problem I believe, and correct me if I am wrong is that my PHP is in the body of the page as shown here:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/iframe page.dwt" codeOutsideHTMLIsLocked="false" -->

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<!-- InstanceBeginEditable name="doctitle" -->

<title>comments</title>

<!-- InstanceEndEditable -->

<link href="styles.css" rel="stylesheet" type="text/css" />

<style type="text/css">

<!--

body {

margin-left: 0px;

margin-top: 0px;

margin-right: 0px;

margin-bottom: 0px;

}

-->

</style>

<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->

</head>

 

<body>

<div id="content"><!-- InstanceBeginEditable name="left" -->

  <div id="contentLeft">

    <p align="center"><img src="images/untitled.JPG" width="118" height="90" /><a href="itpc://djadamash.podOmatic.com/rss2.xml" target="_blank"><img src="http://djadamash.podomatic.com/images/subscribe_with_itunes.gif" width="155" height="44" border="0" align="absbottom" /></a></p>

  </div>

  <!-- InstanceEndEditable --><!-- InstanceBeginEditable name="right" -->

  <div id="contentRight">

    <h1>Comment Me</h1>

    <p>Please leave me a comment below, if you would like to contact me you can so by emailing me on info@djadamash.com - thank you. </p>

<?php include("comments/include.php"); ?>

</div>

  <!-- InstanceEndEditable --></div>

</body>

<!-- InstanceEnd --></html>

 

Moving this to the top of the page works fine, and the comment script works all okay, but I want it to fit into the iFrame like the rest of the site, for continuity, but don't know how to do this, or to get it working right because I now get the error as reported above.

 

I am very new to this so please excuse my ignorance if this is a very simple problem to resolve. My site is www.djadamash.com and the comments section is where the error is present.

 

Please could someone explain to me in simple terms how I can get my comment script into the iFrame and working without this error (if this is at all possible).

 

Thanks for your time.

Adam.

Link to comment
Share on other sites

The error is exactly as it is shown. You have HTML being outputted before the function session_start() is called. This function must be called before anything (even a space) is outputted. You can either move the include up to the very top or if it really needs to be there, you can use output buffering. Add ob_start() at the top and add ob_end_flush() at the end.

Link to comment
Share on other sites

A call to session_start() must occur before any output is sent to the browser.  It would appear that comments/include.php contains a call to session_start(); therefore it has to be at the top of your script, whether you want to put it there or not.

 

Now if comments/include.php creates some output you wish to capture and insert further down in the page, you can do this:

<?php
  ob_start();
  include("comments/include.php");
  $comments = ob_get_contents();
  ob_end_clean();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/iframe page.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
...

 

And then where you currently have your include() statement:

  <?php echo $comments; ?>

Link to comment
Share on other sites

This is what I have now, is this correct?

 

<?php

  ob_start();

  include("comments/include.php");

  $comments = ob_get_contents();

  ob_end_clean();

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/iframe page.dwt" codeOutsideHTMLIsLocked="false" -->

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<!-- InstanceBeginEditable name="doctitle" -->

<title>comments</title>

<!-- InstanceEndEditable -->

<link href="styles.css" rel="stylesheet" type="text/css" />

<style type="text/css">

<!--

body {

margin-left: 0px;

margin-top: 0px;

margin-right: 0px;

margin-bottom: 0px;

}

-->

</style>

<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->

</head>

 

<body>

<div id="content"><!-- InstanceBeginEditable name="left" -->

  <div id="contentLeft">

    <p align="center"><img src="images/untitled.JPG" width="118" height="90" /><a href="itpc://djadamash.podOmatic.com/rss2.xml" target="_blank"><img src="http://djadamash.podomatic.com/images/subscribe_with_itunes.gif" width="155" height="44" border="0" align="absbottom" /></a></p>

  </div>

  <!-- InstanceEndEditable --><!-- InstanceBeginEditable name="right" -->

  <div id="contentRight">

    <h1>Comment Me</h1>

    <p>Please leave me a comment below, if you would like to contact me you can so by emailing me on info@djadamash.com - thank you. </p>

<?php echo $comments; ?>

</div>

  <!-- InstanceEndEditable --></div>

</body>

<!-- InstanceEnd --></html>

Link to comment
Share on other sites

Well what do the instructions say to do?  Do they say, "Include() the file and then call a function?"  Perhaps it's not enough to include() the file, perhaps after you include it you have to call some_mysterious_comment_function().

 

We don't know what you downloaded so we can't tell you how to use it.  In any case your initial problem is resolved and it sounds like it is now a 3rd party script problem, for which we have a dedicated child board.

Link to comment
Share on other sites

From http://www.djadamash.com/comments/docu/docu.html#_Toc151834613

3.      Move the variable $c5t_output from the new include.php file to the place in your existing PHP file where you want the Comment Script content to appear.

echo $c5t_output;

 

It is important that you delete the variable $c5t_output from include.php once you have moved $c5t_output to your existing web page.

 

Can you paste the contents of include.php into a reply?

Link to comment
Share on other sites

Ok.  So the comments stuff is showing up.  It's just not exactly how you'd like it.

 

My first question is, if the pages shown in the iframe are served from the same site, why do you have an iframe to begin with?  If you eliminate the iframe the page will grow to fit it's contents.

 

My second question is, how come you have the height attribute on the iframe set to 480?  That would seem to be why the page is only partially displaying the comments box.  Try a larger setting, like 650, if you are adamant about keeping the iframe.

Link to comment
Share on other sites

Te iFrame is there because I am setting up an affiliate scheme with a music provider to sell music online, and to do this they will be hosting the framework for the site and I will link to it inside the iFrame. I also had a flash banner which streamed my podcast through it.

 

I will adjust the heigh slightly see if that makes any difference

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.