- This topic has 13 replies, 3 voices, and was last updated 5 years, 5 months ago by Tom.
-
AuthorPosts
-
November 13, 2018 at 3:39 am #726005Thomas
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 12You can also download the full debug.log over here (of November the 13th).
Can you please help me fix this?
Best regards,
AlrikNovember 13, 2018 at 6:36 am #726103LeoStaffCustomer SupportHi there,
What version of GP Premium are you using?
You can check in Dashboard > Plugins.
Let me know π
November 13, 2018 at 8:10 am #726359ThomasHi Leo,
Version: 1.7.3 which I believe is the latest?
Wordpress and all other plugins are up to date as well.Best regards,
AlrikNovember 13, 2018 at 8:54 am #726402TomLead DeveloperLead DeveloperThat 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?
November 13, 2018 at 9:08 am #726426ThomasMight 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?
November 13, 2018 at 3:24 pm #726696TomLead DeveloperLead DeveloperIt 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?
November 15, 2018 at 8:22 am #728163ThomasI 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.phpNow 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,
AlrikNovember 15, 2018 at 12:58 pm #728396TomLead DeveloperLead DeveloperYou might want to set your cookies in the
init
hook:add_action( 'init', function() { // Do all cookie setting in this function. } );
November 16, 2018 at 6:21 am #728894ThomasAlright 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,
AlrikNovember 16, 2018 at 9:44 am #729145TomLead DeveloperLead DeveloperIt’s possible that WP_DEBUG isn’t enabled on the other site, so the errors aren’t printing.
November 18, 2018 at 4:50 am #730149ThomasThat 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 );
November 18, 2018 at 10:37 am #730401TomLead DeveloperLead DeveloperNot sure what could cause that then, unfortunately. Could be a server setting?
November 20, 2018 at 7:37 am #732245ThomasThink I figured it out. The actual site has a SSL connection, where the beta doesn’t. Thanks for al the help.
Best regards,
AlrikNovember 20, 2018 at 8:19 am #732284TomLead DeveloperLead DeveloperNo problem! π
-
AuthorPosts
- You must be logged in to reply to this topic.