Zen Follower
- Join Date:
- Apr 2019
- Posts:
- 376
- Plugin Contributions:
- 0
v1.58a with php 8.1, PHP Warning and PHP Deprecated
Greetings. My site just upgraded from 1.57d to 1.58a, and upgraded the php version to 8.1 (finally). I received the following warning from the back end over last night. It seems the following warnings are intermittent, not sure how to trigger it.
Request URI: /index.php?main_page=ask_a_question&action=send&pid=9, IP address: xxxx, Language id 1
#0 public_html/includes/modules/pages/ask_a_question/header_php.php(57): zen_debug_error_handler()
#1 public_html/index.php(35): require('...')
--> PHP Warning: Undefined array key "contactname" in public_html/includes/modules/pages/ask_a_question/header_php.php on line 57.
Request URI: /index.php?main_page=ask_a_question&action=send&pid=9, IP address: xxxx, Language id 1
#0 public_html/includes/modules/pages/ask_a_question/header_php.php(58): zen_debug_error_handler()
#1 public_html/index.php(35): require('...')
--> PHP Warning: Undefined array key "email" in public_html/includes/modules/pages/ask_a_question/header_php.php on line 58.
Request URI: /index.php?main_page=ask_a_question&action=send&pid=9, IP address: xxxx, Language id 1
#0 public_html/includes/modules/pages/ask_a_question/header_php.php(59): zen_debug_error_handler()
#1 public_html/index.php(35): require('...')
--> PHP Warning: Undefined array key "telephone" in public_html/includes/modules/pages/ask_a_question/header_php.php on line 59.
Request URI: /index.php?main_page=ask_a_question&action=send&pid=9, IP address: xxxx, Language id 1
#0 public_html/includes/modules/pages/ask_a_question/header_php.php(60): zen_debug_error_handler()
#1 public_html/index.php(35): require('...')
--> PHP Warning: Undefined array key "enquiry" in public_html/includes/modules/pages/ask_a_question/header_php.php on line 60.
Request URI: /index.php?main_page=checkout_success&action=create_account, IP address: xxxx, Language id 1
#0 public_html/includes/modules/pages/checkout_success/header_php_guest.php(28): zen_debug_error_handler()
#1 public_html/index.php(35): require('...')
--> PHP Warning: Undefined array key "email_format" in public_html/includes/modules/pages/checkout_success/header_php_guest.php on line 28.
Here is my temp solution for the warning above. Change code from
$name = zen_db_prepare_input($_POST['contactname']);
$email_address = zen_db_prepare_input($_POST['email']);
$telephone = zen_db_prepare_input($_POST['telephone']);
$enquiry = zen_db_prepare_input(strip_tags($_POST['enquiry']));
To:
$name = zen_db_prepare_input(($_POST['contactname'] ?? ''));
$email_address = zen_db_prepare_input(($_POST['email'] ?? ''));
$telephone = zen_db_prepare_input(($_POST['telephone']?? ''));
$enquiry = zen_db_prepare_input(strip_tags(($_POST['enquiry']?? '')));
Request URI: /index.php?main_page=ask_a_question&action=send&pid=9, IP address: xxxx, Language id 1
#0 public_html/includes/classes/observers/class.google_recaptcha.php(40): zen_debug_error_handler()
#1 public_html/includes/classes/traits/NotifierManager.php(87): google_recaptcha->update()
#2 public_html/includes/modules/pages/ask_a_question/header_php.php(64): base->notify()
#3 public_html/index.php(35): require('...')
--> PHP Warning: Undefined array key "g-recaptcha-response" in public_html/includes/classes/observers/class.google_recaptcha.php on line 40.
It is related to google google_recaptcha plug-in. Similarly, change code from
$resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
To:
$resp = $recaptcha->verify(($_POST['g-recaptcha-response'] ?? ''), $_SERVER['REMOTE_ADDR']);
Request URI: /index.php?main_page=checkout_success&action=create_account, IP address: xxxx, Language id 1
#0 public_html/includes/modules/pages/checkout_success/header_php_guest.php(28): zen_debug_error_handler()
#1 public_html/index.php(35): require('...')
--> PHP Warning: Undefined array key "email_format" in public_html/includes/modules/pages/checkout_success/header_php_guest.php on line 28.
It is related to OPC 2.5.1. Change code from
$email_format = $_POST['email_format'];
To
$email_format = ($_POST['email_format'] ?? '');
Request URI: /index.php?main_page=ask_a_question&action=send&pid=9, IP address: xxxx, Language id 1
#0 [internal function]: zen_debug_error_handler()
#1 public_html/includes/functions/functions_email.php(720): substr_count()
#2 public_html/includes/modules/pages/ask_a_question/header_php.php(66): zen_validate_email()
#3 public_html/index.php(35): require('...')
--> PHP Deprecated: substr_count(): Passing null to parameter #1 ($haystack) of type string is deprecated in public_html/includes/functions/functions_email.php on line 720.
Change code from
if (substr_count($email,'@') != 1) return false;
To
if (substr_count(($email ?? ''),'@') != 1) return false;
If you have a better idea to solve those warnings, please let me know.