Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Dec 2012
    Posts
    54
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Getting session start error message

    First, I have the following contact.php
    PHP Code:
    <?php session_start();
    // get variables
    $name=$_REQUEST["name"];
    $email=$_REQUEST["email"];
    $message=$_REQUEST["message"];
    if (isset(
    $_REQUEST["Submit"])) {
    // now to check whether the verify code is correct
        
    if ($_POST["vercode"] != $_SESSION["vercode"] OR $_SESSION["vercode"]=='')  {
            echo  
    "<script language='javascript' type='text/javascript'>alert('Please enter the correct verifiction code.');</script>";
        } else if(!
    eregi('^([a-z0-9\._-])+@([^\.]+\.[^\.]+)'$_REQUEST["email"], $matched)) {
             echo  
    "<script language='javascript' type='text/javascript'>alert('Please enter a correct email address.');</script>";
        } else {
    // this is where you want your contact for to be sent
    // you may put in multiple emails using a comma between them
    // IT IS IMPORTANT THAT YOU CHANGE THIS TO YOUR EMAIL ADRESS
    $recip "my@email.com";
    $message str_replace("\r""\n"$message);
    $senderip=$_SERVER['REMOTE_ADDR'];
    // get the senders ip just in case
    $subject "New Message";
    // your content of the message
    $mailbody "Contact form sent by
    Name: $name
    Email: $email
    Message:
    $message
    -------
    sender's ip: $senderip"
    ;
    // now to send the email off
        
    if (mail($recip$subject$mailbody"From: $email")) {
             
    // add form data processing code here
             
    echo  "<script language='javascript' type='text/javascript'>alert('Your email has been sent..');</script>";
        }
    }
    }
    ?>
    <form action="contact.php" method="post">
                <strong>Name:</strong><br>
                  <input name="name" type="text" id="name" size="30"  />
                  <br>
                  <br>
                  <strong>Email:</strong><BR>
                  <input name="email" type="text" id="email" size="30"  />
                  <br>
                  <br>
     
                  <strong>Message:</strong><BR>
                  <textarea name="message" cols="30" rows="4" ></textarea>
     
                  <br>
                  <br>
                  <strong>Please type in the  verification code: </strong><BR>
                  <img src="captcha.php" /><br>
                  <input name="vercode" type="text" size="30" />
     
                  <BR>
                  <br>
                  <br>
     
                  <input type="submit" name="Reset" value="Reset">
                  &nbsp;
                  <input type="submit" name="Submit" value="Submit">
                  <br>
                  <br>
     
            </form>
    I have this page being included in my template with the following code:
    PHP Code:
    <?php include('contact.php'); ?>
    When I load my template page I get the form to display, but the following error appears at the top:
    Code:
    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at contact.html:9) in contact.php on line 1
    From my searching, this is because of whitespace (or so I think), but there is no whitespace I can tell in contact.php. If this is because I am including the page in another and calling it with a tag, is there anyway around this error?

  • #2
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,386
    Thanks
    8
    Thanked 1,077 Times in 1,068 Posts
    When you "include" it, you need to do that the very first thing, before you output (or buffer) any lines (HTML) to the browser.

    Try eliminating this: session_start(); on your contact.php script and then put it on the very first line of your template page.

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by mharrison View Post
    First, I have the following contact.php
    PHP Code:
    <?php session_start();
    I have this page being included in my template with the following code:
    PHP Code:
    <?php include('contact.php'); ?>
    What is the source for the file that includes contact.php? - Somewhere in there you are outputting something which is triggering the webserver to send headers. If your page is encoded in utf-8 make sure it's done without bom as that will trigger it but you can't see it in your editor
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #4
    New Coder
    Join Date
    Dec 2012
    Posts
    54
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Here is the source of my template that is including the contact.php file.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
      <meta content="text/html; charset=ISO-8859-1"
     http-equiv="content-type">
      <title>Template</title>
    </head>
    <body>
    <table
     style="width: 1300px; text-align: left; margin-left: auto; margin-right: auto;"
     border="0" cellpadding="2" cellspacing="2">
      <tbody>
        <tr>
          <td colspan="3" rowspan="1"
     style="vertical-align: top; text-align: center;"><?php include('Banner.html'); ?>
          </td>
        </tr>
        <tr>
          <td colspan="3" rowspan="1" align="center"
     valign="top">
    <?php include('Buttons.html'); ?></td>
        </tr>
        <tr>
          <td style="text-align: center; vertical-align: top;"
     colspan="3"><?php include('Row1.html'); ?></td>
        </tr>
        <tr>
        </tr>
           <tr>
          <td style="text-align: center; vertical-align: top;"
     colspan="3"><?php include('Row2.html'); ?></td>
        </tr>
        <tr>
          <td
     style="width: 130px; text-align: left; vertical-align: top;"><?php include('LeftBar.html'); ?></td>
          <td style="vertical-align: top;"><?php include('contact.php'); ?><br>
          </td>
          <td
     style="width: 310px; text-align: center; vertical-align: top;"><?php include('AdsBar.html'); ?></td>
        </tr>
        <tr>
          <td style="text-align: center; vertical-align: middle;"
     colspan="3"><?php include('Row3.html'); ?></td>
        </tr>
        <tr>
          <td style="text-align: center; vertical-align: middle;"
     colspan="3"><?php include('Row4.html'); ?></td>
        </tr>
      </tbody>
    </table>
    </body>
    </html>

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by mharrison View Post
    Here is the source of my template that is including the contact.php file.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
      <meta content="text/html; charset=ISO-8859-1"
     http-equiv="content-type">
      <title>Template</title>
    </head>
    <body>
    <table
     style="width: 1300px; text-align: left; margin-left: auto; margin-right: auto;"
     border="0" cellpadding="2" cellspacing="2">
      <tbody>
        <tr>
          <td colspan="3" rowspan="1"
     style="vertical-align: top; text-align: center;"><?php include('Banner.html'); ?>
          </td>
        </tr>
        <tr>
          <td colspan="3" rowspan="1" align="center"
     valign="top">
    <?php include('Buttons.html'); ?></td>
        </tr>
        <tr>
          <td style="text-align: center; vertical-align: top;"
     colspan="3"><?php include('Row1.html'); ?></td>
        </tr>
        <tr>
        </tr>
           <tr>
          <td style="text-align: center; vertical-align: top;"
     colspan="3"><?php include('Row2.html'); ?></td>
        </tr>
        <tr>
          <td
     style="width: 130px; text-align: left; vertical-align: top;"><?php include('LeftBar.html'); ?></td>
          <td style="vertical-align: top;"><?php include('contact.php'); ?>
    Er yeah, thats your problem right there. A whole ton of html output. No idea why you were thinking about whitespace when you have so much other output. session_start() MUST be called before any output at all. There is a link in my signature that explains this. You clearly have some idea how this works as you were talking about the whitespace so I'm not sure how you've misunderstood the html output.

    Anyway either add session_start() to the top of this before your opening html tag OR use output buffering instead. See the link in my signature
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #6
    New Coder
    Join Date
    Dec 2012
    Posts
    54
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    Anyway either add session_start() to the top of this before your opening html tag OR use output buffering instead. See the link in my signature
    I was thinking whitespace because I'm still fairly new so I wasn't sure if the whitespace meant in the contact.php or the template page, since it was calling the php page.

  • #7
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    No in your case, the output is the html source from the file including contact.php. ANYTHING that is sent to the browser before a cookie function will screw it up. Cookies are sent in the headers. session_start() sends a cookie so by having your output go to the browser before your call to session_start(), the cookie can't be sent in the headers.

    Check the link in my signature for more.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #8
    New Coder
    Join Date
    Dec 2012
    Posts
    54
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    No in your case, the output is the html source from the file including contact.php. ANYTHING that is sent to the browser before a cookie function will screw it up. Cookies are sent in the headers. session_start() sends a cookie so by having your output go to the browser before your call to session_start(), the cookie can't be sent in the headers.

    Check the link in my signature for more.
    I tried adding the session_state() on my template page before the HTML tag and all it did was move the error to the very top of the page and stop my captcha image from loading.

    This is all a bit over my head at this point so I'm just going to scrap the script that I found and look for something different.

    //Edit

    Ok, so I got the error to go away, but doing so breaks the form so it does not submit anymore. I'm just giving up on this script...I'll figure something else out.

    Thanks for the help you provided.
    Last edited by mharrison; 03-12-2013 at 03:49 AM. Reason: More Info

  • #9
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Don't scrap it, tell us more about the symptoms and we will help.

    It will be a few hours though as I'm off to bed! (almost 3am here)
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • Users who have thanked tangoforce for this post:

    mharrison (03-12-2013)

  • #10
    New Coder
    Join Date
    Dec 2012
    Posts
    54
    Thanks
    12
    Thanked 0 Times in 0 Posts
    A smoke and a beer later and I got it all figured out....sometimes it is true...you just have to walk away, clear your head, and start again.

    Instead of calling the contact.php, I just put the php and form code right into my template where it used to call the contact.php file. I removed the session_start() from the original code, leaving just the <?php and then on the very first line of the template I put the <?PHP
    session_start(); ?> and what do you know, it works fine now.

    Again, thanks for the help. This all might be a bit beyond my skill set currently, but I am a very fast learner.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •