views:

81

answers:

5
<div id="left-body-part-innerpage">
    <h1 class="mainheading">Contact Us</h1>
    <div id="contactus-right-div" class="content">
    <?php session_start();
        if( isset($_POST['button2']))           
        {
            if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) 
            {
                $name = $_POST['name'];
                // Insert you code for processing the form here, e.g emailing the submission, entering it into a database. 
                session_destroy();
                header("Location: contactdb.php");
?>

i am getting Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at website) in website

Warning: Cannot modify header information - headers already sent by (output started at website) in website

can any one help me?

Thanks in advance....

+4  A: 
  1. Starting a session requires setting HTTP headers
  2. You can't send headers after you have sent content
  3. Anything outside <?php and ?> constitutes content (as does anything you echo, print, etc)

Move your session code to the top of the script.

David Dorward
hi david,i have moved session_start() at the beginning of my page but i am still getting the same warnings.
Rachel
@Rachel have you moved the whole code block to the very beginning of the page?
Pekka
Believe it or not, the `header` function also sends headers which can't appear after content.
David Dorward
Rachel
@Rachel you absolutely can and must put it to the top of the page. You can not start a page redirect once HTML has been output. You may have to rewrite the whole thing a bit in order to display an error message if the captcha doesn't match but that `header()` command *must* come before amnything is output.
Pekka
how would it check the captcha security? i am not getting what you are saying
Rachel
<?php ob_start();session_start(); $security_code = $_SESSION['security_code']; session_destroy();?>i have put this code in the starting of the page and than i have put this code<?php if( isset($_POST['button2'])) {if( $security_code == $_POST['security_code']else {echo '<div class=error-text> Sorry, you have provided an invalid security code </div> <br/>'; ?>but still the same output :(
Rachel
I don't really know how the captcha would work, but one thing is certain: It isn't going to involve loading half a page, pausing the PHP script, waiting for the user to type in the answer to the captcha and then resuming the page. HTTP doesn't work like that. You would normally present the capcha on one page with a form, then another script would process the results of that once the user hits submit to make a new HTTP request.
David Dorward
+1  A: 

all work with session, cookies, header() etc(everything that modifies http headers) must be done before first output of the script... put your php block before the markup

<?php session_start();
    if( isset($_POST['button2']))           
    {
        if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) 
        {
            $name = $_POST['name'];
            // Insert you code for processing the form here, e.g emailing the submission, entering it into a database. 
            session_destroy();
            header("Location: contactdb.php");?>

<div id="left-body-part-innerpage">
<h1 class="mainheading">Contact Us</h1>
<div id="contactus-right-div" class="content">
kgb
A: 

Hi,

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at website) in website

Warning: Cannot modify header information - headers already sent by (output started at website) in website

Regarding this two issue :

--- Use session start in top of your code. Before that you can use ob_start() for output buffer clearing.

Like,

<?php
ob_start();
session_start();
?>
Karthik
A: 

As a general rule, do all business logic first (such as session management) before starting output of content.

As already pointed out, starting to print page content will automatically send headers.

Fredrik
A: 

Use output buffering to prevent output before you send headers.

<?php

function callback($buffer) {

  // заменить все apples на oranges
  return (ereg_replace("apples", "oranges", $buffer));

}

ob_start("callback");
//HERE you can send any headers you want. callback is not required here if you don't want
?>

<html>
<body>
<p>It's like comparing apples to oranges.
</body>
</html>

<?php
//And here you can
ob_end_flush();
//If send headers here - you'll get warning
?>
GOsha