#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    136
    Rep Power
    13

    Session_start issue


    Hi all im having issues with session_start on a phpcapcha enabled form, and im getting the error
    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/public_html/send.php:1) in /home/public_html/send.php on line 1
    no i know this is usually down to whitespace before the session tag but there is no whitespace in the code:

    PHP Code:
    <?php session_start(); ?>
    <div id="content">
    &nbsp;<h2><img src="images/title.jpg" alt="header" width="63" height="20" />Contact Us - Confirmation</h2>
    <p>&nbsp;</p>
    <?php
    include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage.php';
    $securimage = new Securimage();

      if (
    $securimage->check($_POST['captcha_code']) == false) {
      
    // the code was incorrect
      // handle the error accordingly with your other error checking

      // or you can do something really basic like this
      
    die('The code you entered was incorrect.  Go back and try again.');
    }
    ?>
    any help would be great

    Craig
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2008
    Posts
    577
    Rep Power
    184
    I'm assuming that in
    $_SERVER['DOCUMENT_ROOT'] . '/securimage.php';

    You have some security checks and then you use Header(Location) to redirect a user based on the criteria. If that is the case then include the file at the top where you start the session. Because you can't have any output to the screen when using headers without like some ob_start crap.

    PHP Code:

    <?php session_start();
    include_once 
    $_SERVER['DOCUMENT_ROOT'] . '/securimage.php'?>

    <div id="content">
    &nbsp;<h2><img src="images/title.jpg" alt="header" width="63" height="20" />Contact Us - Confirmation</h2>
    <p>&nbsp;</p>
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    136
    Rep Power
    13
    i understand what you are saying, but we are using phpcapcha on other sites, the same code implemented the same way, but its only here it gives this issue.

    Craig
  6. #4
  7. Banned

    Join Date
    Jul 2004
    Location
    The Mews At Windsor Heights
    Posts
    5,326
    Rep Power
    0
    If ouput_buffering is enabled in php.ini then a script can send headers even after there has been output.

    Are the other sites on different servers? If so then maybe the other servers had output_buffering enabled and this one doesn't.
  8. #5
  9. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,304
    Rep Power
    7173
    securimage.php shouldn't be causing any problems because it isn't called until after the line where the header issue is occurring.

    This error is somewhat strange, are you sure you don't have any new lines before your opening PHP tag? If you call exit; immediately after session_start and view the source of the page in your web browser does it show anything before the error message?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    136
    Rep Power
    13
    ok i called the exit as you said, viewed the src and heres what i got:

    <br />
    <b>Warning</b>: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/bugsyca/public_html/send.php:1) in <b>/home/bugsyca/public_html/send.php</b> on line <b>1</b><br />
    should it put the <br> in...?

    Craig
  12. #7
  13. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2004
    Location
    Kostolac, Serbia
    Posts
    855
    Rep Power
    1394
    One possible cause for this might be that you are using one of the older versions of Dreamweaver for your coding which used to insert a BOM character at the very beginning of the file. That caused PHP to report that content is already sent prior to the headers. To tell you the truth the only thing that would not fit best in your story with my assumption is the fact that you already have a site running with the same code. On the other hand if you made only minor modifications to the scripts that don't work as expected (simple additional "Save" would be enough) then it might have something to do with the fact that BOM was inserted during one of the saves.

    To solve this problem usually it would be enough to copy/paste the complete page code to a new php file in DW and save it. In cases when this would not work you would have to use Notepad or Notepad++ and repeat the copy/paste/save procedure there.

    This used to drive me crazy in those days when I used DW just to make some alterations to the HTML that contained small portions of PHP code and DW simply used to hide a BOM character at the very beginning of the file.

    Comments on this post

    • kicken agrees : Sounds like a problem with a BOM character to me.
    Last edited by holodoc; April 14th, 2009 at 08:52 AM.
    PHP Code:
    <?php
    abstract class Ignorance extends Stupidity implements Unavoidable 
         public static 
    $humiliation

         private function 
    __construct(){
            
    parent::__destruct();
         }; 

    ?>
  14. #8
  15. User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2005
    Location
    UK
    Posts
    471
    Rep Power
    76
    Try
    PHP Code:
    if(!isset($_SESSION)){session_start();} 
    Your error may be because it's trying to start a session when there is already one started.

    Comments on this post

    • kicken disagrees : [0] Starting a session multiple times wouldn't cause that error

IMN logo majestic logo threadwatch logo seochat tools logo