PHP session_start error

Discussion in 'PHP' started by sam20e, Jan 18, 2013.

  1. #1
    hi

    I have stored my db details in a file called config.php


    config.php

    <?php
    session_start();
    //error_reporting(E_ALL);
    ini_set('display_errors',0);
    	
    	$glob['dbhost'] = "localhost";
    .....
    .....
    .....
    
    PHP:
    I have a cron file which runs perfectly fine.

    Cron.php


    
    <?php include("inc/config.php");
    
    $to_mail = 'myemail@gmail';
    $sql=$dclass->select('*','tbl_test');
    .....
    .....
    .....
    
    PHP:
    This cron works perfectly fine. Now i need another cron file. I copied the same exact content of this cron file and created a new cron file called cron2.php and set the cron timing to every 1 minutes and i got this error in the error log

    [18-Jan-2013 20:30:01] PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent in /home/xxxxx/public_html/xxxx/inc/config.php on line 2
    [18-Jan-2013 20:30:01] PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent in /home/xxxxx/public_html/xxxx/inc/config.php on line 2


    I really don't understand how come if its 1 cron file its working flawlessly and if its 2 different cron files it gives this error. Can anyone suggest a work around?

    Thanks
    Sam
     
    sam20e, Jan 18, 2013 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    Are you sure the file isn't something like
    
    
    
    <?php include("inc/config.php");
    
    $to_mail = 'myemail@gmail';
    $sql=$dclass->select('*','tbl_test');
    .....
    .....
    .....
    
    Code (markup):
    That blank line will send headers, so you can't send headers in your code unless you have output buffering on. (Just make sure that the include comes before any printable content, like a blank line.)
     
    Rukbat, Jan 18, 2013 IP
  3. sam20e

    sam20e Member

    Messages:
    57
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #3

    i can confirm there is no blank line before <?php include("inc/config.php");
     
    sam20e, Jan 18, 2013 IP
  4. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #4
    copy and paste the file into a new one and i think it will work, sometimes you have invisable characters (i have been there...)
     
    EricBruggema, Jan 18, 2013 IP
  5. xtmx

    xtmx Active Member

    Messages:
    359
    Likes Received:
    12
    Best Answers:
    4
    Trophy Points:
    88
    #5
    If all else fails, try changing config.php to

     
    xtmx, Jan 19, 2013 IP