1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

False Positive for Error in Header... How to stop it displaying?

Discussion in 'PHP' started by WebDev Solutions, Oct 13, 2015.

  1. #1
    Afternoon ladies & gents,

    We've installed a mobile version of our website. The main website and the mobile version redirect are working flawlessly, but it has caused the following error to appear in the header;

    Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Inetpub\vhosts\stowfordmanorfarm.co.uk\httpdocs\index.php:1) in C:\Inetpub\vhosts\stowfordmanorfarm.co.uk\httpdocs\concrete\startup\session.php on line 32
    
    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Inetpub\vhosts\stowfordmanorfarm.co.uk\httpdocs\index.php:1) in C:\Inetpub\vhosts\stowfordmanorfarm.co.uk\httpdocs\concrete\startup\session.php on line 32
    Code (markup):

    Naturally, I've ensured the site is working perfectly .. so now I'd like to simply hide these errors from publicly displaying in the header. Can somebody assist?

    Website:
    http://stowfordmanorfarm.co.uk/
    Code (markup):
    WebDev
     
    WebDev Solutions, Oct 13, 2015 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    You have started / used session_start() without checking if session is already present. Amend your code (probably in the sessions.php-file) to something like
    
    if (!session_id()) {
      session_start();
    }
    
    PHP:
    And no, your site is not "working flawlessly" when you have an error showing up.
     
    PoPSiCLe, Oct 13, 2015 IP
  3. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #3
    Or you have a UTF-BOM at the start of your script.. :) that outputs some bytes to the browser so sessions can't be started...
     
    EricBruggema, Oct 19, 2015 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #4
    Or even just something as simple as a carriage return before your first <?

    Remember, ANY content output before you try to start the session means headers are already sent!

    There's a reason when writing PHP I prefer to have only oneand ONLY ONE <?php per FILE and have it the VERY first thing in said file.... instead of the willy-nilly <?php ?><?php ?><?php ?><?php ?><?php ?><?php ?><?php ?><?php ?><?php ?><?php ?><?php ?> You see in people's code that they are under the delusion is good practice.

    In your case it looks like you are sending this:

    <script src="redirect.js"></script>
    <script>
    SA.redirection_mobile ({
    noredirection_param:"full",
    //tablet_redirection : "true",
    mobile_url : "m.stowfordmanorfarm.co.uk",
    mobile_prefix : "http",
    cookie_hours : "1"
    });
    </script>
    Code (markup):
    Before you've even sent the doctype! Script doesn't go there!!! Suppressing the error is not a fix, NOR is it a "false positive" -- that's proof positive that there's something disastrously wrong with your PHP.
     
    deathshadow, Oct 21, 2015 IP
    KangBroke likes this.
  5. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #5
    Well... he's also using a mobile-subdomain, which I was hoping was going the way of the dodo at least 5 years ago. There is not really any reason to use a mobile subdomain unless you have completely different content for mobile and desktop (which few have) - and even then that can usually be solved with smart programming of the site.
     
    PoPSiCLe, Oct 22, 2015 IP
  6. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #6
    Which really is something that never should have existed in the first place -- see the nonsense of WAP and/or WML; the entire POINT of HTML was to be device neutral, it's just most people couldn't pull their heads out of photoshop jockey's ass to realize it. The scripttard redirect for mobile, subdomains just for mobile, it all completely misses the entire reason HTML even exists.

    ... as does it seem most people building websites these days.

    So yeah, it should have faced extinction the moment responsive layout became real world deployable -- if not sooner.

    Of course it's also a tranny document -- and as we often say that quite literally means "in transition from 1997 to 1998 coding practices" so...
     
    deathshadow, Oct 22, 2015 IP