[Resolved] a lot of PHP warnings in my debug.log

Home Forums Support [Resolved] a lot of PHP warnings in my debug.log

Home Forums Support a lot of PHP warnings in my debug.log

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #726005
    Thomas

    Hi there,

    Due to some performance issues I decided to activate the debug log of wordpress. It shows a lot of PHP warnings which (I think/believe) have to do something with GP. Now I can’t tell you when these errors first appeared since I’m running the debug.log only since yesterday. To provide some more information here is a section of my debug.log

    [13-Nov-2018 11:20:08 UTC] PHP Warning: Cannot modify header information – headers already sent by (output started at /home/vespacia/public_html/wp-includes/formatting.php:5103) in /home/vespacia/public_html/wp-content/plugins/gp-premium/hooks/functions/hooks.php(22) : eval()’d code on line 5
    [13-Nov-2018 11:20:08 UTC] PHP Warning: Cannot modify header information – headers already sent by (output started at /home/vespacia/public_html/wp-includes/formatting.php:5103) in /home/vespacia/public_html/wp-content/plugins/gp-premium/hooks/functions/hooks.php(22) : eval()’d code on line 12
    [13-Nov-2018 11:20:14 UTC] PHP Warning: Cannot modify header information – headers already sent by (output started at /home/vespacia/public_html/wp-includes/formatting.php:5103) in /home/vespacia/public_html/wp-content/plugins/gp-premium/hooks/functions/hooks.php(22) : eval()’d code on line 5
    [13-Nov-2018 11:20:14 UTC] PHP Warning: Cannot modify header information – headers already sent by (output started at /home/vespacia/public_html/wp-includes/formatting.php:5103) in /home/vespacia/public_html/wp-content/plugins/gp-premium/hooks/functions/hooks.php(22) : eval()’d code on line 12

    You can also download the full debug.log over here (of November the 13th).

    Can you please help me fix this?

    Best regards,
    Alrik

    #726103
    Leo
    Staff
    Customer Support

    Hi there,

    What version of GP Premium are you using?

    You can check in Dashboard > Plugins.

    Let me know πŸ™‚

    #726359
    Thomas

    Hi Leo,

    Version: 1.7.3 which I believe is the latest?
    Wordpress and all other plugins are up to date as well.

    Best regards,
    Alrik

    #726402
    Tom
    Lead Developer
    Lead Developer

    That looks like you have some errors in your PHP which you’ve added into GP Hooks (Appearance > Hooks).

    What PHP do you have in there?

    #726426
    Thomas

    Might not be the most pretty code because I just started to learn myself some php but I don’t believe there are any errors? This code is placed in Before header

    <?php
    // if cookie vc_last_visit does not exist or is empty
    if(!isset($_COOKIE['vc_last_visit']) || $_COOKIE['vc_last_visit'] === '') {
    	$set_last = time() + 3600;
    	setcookie('vc_last_visit', $set_last, time() + 2629746, '/'); // 1 month
    }
    // If cookie vc_temporary does not exist or is empty
    if(!isset($_COOKIE['vc_temporary']) || $_COOKIE['vc_temporary'] === '') {
    	// If vc_last_visit does not exist
    	if(!isset($_COOKIE['vc_last_visit'])) {
    		$set_temp = strtotime('-1 week') + 3600; // set vc_temporary to 1 week ago
    		setcookie('vc_temporary', $set_temp, 0, '/'); // valid untill end session
    	// Else if vc_last_visit does exist
    	} else {
    		$set_temp = $_COOKIE['vc_last_visit'];
    		setcookie('vc_temporary', $set_temp, 0, '/'); // valid untill end session
    	}
    }
    // if cookie vc_last_visit exist reset
    if(isset($_COOKIE['vc_last_visit'])) {
    	$set_last = time() + 3600;
    	setcookie('vc_last_visit', $set_last, time() + 2629746, '/'); // 1 month
    }
    ?>

    The pages on which these cookies are used are not of any relevance right?

    #726696
    Tom
    Lead Developer
    Lead Developer

    It shouldn’t, but it depends on how you’re specifying the pages.

    The debug errors are pointing directly at the code being executed by GP Hooks, so it’s likely coming from in there somewhere. If you remove that code and empty your debug log, do errors continue to generate?

    #728163
    Thomas

    I removed the code and most errors disappeared. Of course I got some new undefined indexes because of it so it would be nice to be able to place the code back again.

    I did notice more or less the same error, this time revering to a page I wrote.

    [15-Nov-2018 15:09:49 UTC] PHP Warning: Cannot modify header information – headers already sent by (output started at /…/wp-includes/formatting.php:4999) in /…/themes/generatepress-child/search.php on line 115

    line 115 containing setcookie('VCsearchpage', $keyword . ';' . $search_show . ';' . $search_sort);

    So setcookie() seems to be the cause.

    cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html> and <head> tags as well as any whitespace.
    Source: http://php.net/manual/en/function.setcookie.php

    Now we figured this out I’m wondering whether I need to address WordPress for help instead? But if you guys know of a way to set cookies before any other output it would be much appreciated.

    Best regards,
    Alrik

    #728396
    Tom
    Lead Developer
    Lead Developer

    You might want to set your cookies in the init hook:

    add_action( 'init', function() {
        // Do all cookie setting in this function.
    } );
    #728894
    Thomas

    Alright that fixes it, happy with that!

    But I hate things I can’t explain. I’m running the exact same code on a secondary website for testing. This website is a copy of the actual site, running the same plugins and code, no differance. On this beta-platform I can run the code without the init hook, producing no errors.

    Edit: I placed it inside functions.php instead of GP hooks now.

    Do you guys have an explanation for this? I’ll mark this topic as resolved as it is, but hopefully you can answer this question anyway.

    Best regards,
    Alrik

    #729145
    Tom
    Lead Developer
    Lead Developer

    It’s possible that WP_DEBUG isn’t enabled on the other site, so the errors aren’t printing.

    #730149
    Thomas

    That would be possible πŸ˜‰ but wp_dubug is running

    define('WP_DEBUG', true);
    define('WP_DEBUG_LOG', true);
    /* wp_debug_display false, otherwise errors will be printed for users as well */
    define('WP_DEBUG_DISPLAY', false);
    @ini_set( 'display_errors', 0 );
    #730401
    Tom
    Lead Developer
    Lead Developer

    Not sure what could cause that then, unfortunately. Could be a server setting?

    #732245
    Thomas

    Think I figured it out. The actual site has a SSL connection, where the beta doesn’t. Thanks for al the help.

    Best regards,
    Alrik

    #732284
    Tom
    Lead Developer
    Lead Developer

    No problem! πŸ™‚

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.