Site logo

Archived topic

a lot of PHP warnings in my debug.log

13 replies · Started by Thomas on November 13, 2018

Viewing posts 1–14 of 14

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

Hi there,

What version of GP Premium are you using?

You can check in Dashboard > Plugins.

Let me know :)

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

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?

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?

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?

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

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

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

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

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

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 );

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

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

No problem! :)

This archived topic is closed to new replies.