Forum Archive - Warnings on array parameter and headers already sent by

Warnings on array parameter and headers already sent by
May 26, 2016 1:31 pm by acyba
Hello, I think there is an issue when you have a 2 levels array parameter in your URL. For example an URL like [url]http://www.mydomain.com?param[lvl1][lvl2]=value[/url] There are the following warnings when trying to translate the page: Warning: urlencode() expects parameter 1 to be string, array given in /srv/www/vhosts/www.domain.com/www/gtranslate/gtranslate.php on line 25 Warning: Cannot modify header information - headers already sent by (output started at /srv/www/vhosts/www.domain.com/www/gtranslate/gtranslate.php:25) in /srv/www/vhosts/www.domain.com/www/gtranslate/gtranslate.php on line 141 How can we solve this? Best regards
Re: Warnings on array parameter and headers already sent by
May 26, 2016 5:36 pm by Edvard
Hi, Can you provide a link to live example? Thanks!
Re: Warnings on array parameter and headers already sent by
May 27, 2016 8:46 am by acyba
Hello, Sure, here is a link: [url]https://www.acyba.com/fr/?param[lvl1][lvl2]=value[/url] You will have the same issue on any page of the site if you add this kind of parameter in the URL. Best regards
Re: Warnings on array parameter and headers already sent by
May 27, 2016 6:50 pm by Edvard
Hi, Try to replace $get_params = array(); foreach($_GET as $key => $val) { if($key != 'glang' and $key != 'gurl') { if(is_array($val)) foreach($val as $v) $get_params[] = $key.'[]='.urlencode($v); else $get_params[] = $key.'='.urlencode($val); } } if(count($get_params)) { $page_url .= '?' . implode('&', $get_params); } with $get_params = $_GET; if(isset($get_params['glang'])) unset($get_params['glang']); if(isset($get_params['gurl'])) unset($get_params['gurl']); if(count($get_params)) { $page_url .= '?' . http_build_query($get_params); } in gtranslate/gtranslate.php file.
Re: Warnings on array parameter and headers already sent by
May 31, 2016 7:22 am by acyba
Hello, Thanks a lot for this code. This is now working. Best regards
Re: Warnings on array parameter and headers already sent by
May 31, 2016 5:00 pm by Edvard
You are welcome. Good to hear that.

SIMILAR TOPICS

Change language using a URL parameter: site.com?lang=DEJan 4, 2018 4:16 pmReplies: 4Post by: jivan
Adding html language code to page headersAug 13, 2015 4:40 pmReplies: 1Post by: mjbradley85
PHP Strict Standards warningsJun 2, 2015 3:29 amReplies: 2Post by: helgatheviking
Warning: trim() expects parameter 1 to be string, array giveMar 30, 2015 5:14 pmReplies: 11Post by: ejb01
Several "Strict Standards" warnings on WP-ADMIN UpdateJan 20, 2015 7:20 amReplies: 2Post by: pfmoser

Try GTranslate with a free 15 day trial