Title: PHP Warning: Undefined array key &#8220;HTTP_USER_AGENT&#8221;
Last modified: February 8, 2025

---

# PHP Warning: Undefined array key “HTTP_USER_AGENT”

 *  [al3ilm](https://wordpress.org/support/users/al3ilm/)
 * (@al3ilm)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/php-warning-undefined-array-key-http_user_agent-5/)
 * **Fixing the Issue with Adding wp-hijri in the hijri-widgets.php File**
 * **Error Message:**
 *     ```wp-block-code
       [21-Dec-2024 10:30:11 UTC] PHP Warning:  Undefined array key "HTTP_USER_AGENT" in /home/mfkvhsiieh/public_html/wp-content/plugins/wp-hijri/include/hijri-widgets.php on line 317
       ```
   
 * **Original Code with the Issue:**
 *     ```wp-block-code
       if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false)
           $ak_title_separator = "\n";
       else
           $ak_title_separator = ', ';
   
       $ak_titles_for_day = array();
       $ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as d , MONTH(post_date) AS m,YEAR(post_date) AS y "
               . "FROM $wpdb->posts "
               . "WHERE post_date >= '{$gy1}-{$gm1}-{$gd1} 00:00:00' "
               . "AND post_date <= '{$gy2}-{$gm2}-{$gd2} 23:59:59' "
               . "AND post_type = 'post' AND post_status = 'publish'"
       );
       if ($ak_post_titles) {
           foreach ((array) $ak_post_titles as $ak_post_title) {
   
               /** This filter is documented in wp-includes/post-template.php */
               $post_title = esc_attr(apply_filters('the_title', $ak_post_title->post_title, $ak_post_title->ID));
               $dt=new \hijri\datetime($ak_post_title->y . '-' . zeroise($ak_post_title->m, 2) . '-' . zeroise($ak_post_title->d, 2), NULL, NULL, $hcal);
               $hd = $dt->format('_j');
               if (empty($ak_titles_for_day['day_' . $hd]))
                   $ak_titles_for_day['day_' . $hd] = '';
               if (empty($ak_titles_for_day["$hd"])) // first one
                   $ak_titles_for_day["$hd"] = $post_title;
               else
                   $ak_titles_for_day["$hd"] .= $ak_title_separator . $post_title;
           }
       }
       ```
   
 * **Revised Code:**
 *     ```wp-block-code
       if (isset($_SERVER['HTTP_USER_AGENT']) && 
           (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || 
            stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || 
            stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false)) {
           $ak_title_separator = "\n";
       } else {
           $ak_title_separator = ', ';
       }
   
       $ak_titles_for_day = array();
       $ak_post_titles = $wpdb->get_results(
           "SELECT ID, post_title, DAYOFMONTH(post_date) as d, MONTH(post_date) AS m, YEAR(post_date) AS y " .
           "FROM $wpdb->posts " .
           "WHERE post_date >= '{$gy1}-{$gm1}-{$gd1} 00:00:00' " .
           "AND post_date <= '{$gy2}-{$gm2}-{$gd2} 23:59:59' " .
           "AND post_type = 'post' AND post_status = 'publish'"
       );
   
       if ($ak_post_titles) {
           foreach ((array) $ak_post_titles as $ak_post_title) {
               /** This filter is documented in wp-includes/post-template.php */
               $post_title = esc_attr(apply_filters('the_title', $ak_post_title->post_title, $ak_post_title->ID));
               $dt = new \hijri\datetime($ak_post_title->y . '-' . zeroise($ak_post_title->m, 2) . '-' . zeroise($ak_post_title->d, 2), NULL, NULL, $hcal);
               $hd = $dt->format('_j');
               if (empty($ak_titles_for_day['day_' . $hd])) {
                   $ak_titles_for_day['day_' . $hd] = '';
               }
               if (empty($ak_titles_for_day["$hd"])) { // first one
                   $ak_titles_for_day["$hd"] = $post_title;
               } else {
                   $ak_titles_for_day["$hd"] .= $ak_title_separator . $post_title;
               }
           }
       }
       ```
   
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fphp-warning-undefined-array-key-http_user_agent-5%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

The topic ‘PHP Warning: Undefined array key “HTTP_USER_AGENT”’ is closed to new 
replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wp-hijri_fbfbfb.svg)
 * [WP-Hijri](https://wordpress.org/plugins/wp-hijri/)
 * [Support Threads](https://wordpress.org/support/plugin/wp-hijri/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-hijri/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-hijri/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-hijri/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [al3ilm](https://wordpress.org/support/users/al3ilm/)
 * Last activity: [1 year, 3 months ago](https://wordpress.org/support/topic/php-warning-undefined-array-key-http_user_agent-5/)
 * Status: not a support question