Tag Archives: PHP

Fix for Duplicate Headers Error 349

Duplicate Headers Error 349 (net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)

This error was bugging me whole of last week. This error is specific to Google Chrome. Not a bug in chrome itself though, as other browsers ignore duplicate headers, this seems like an issue with Chrome. This can be addressed easily the following ways, if you or your web app is sending out headers.

1. Enclose filename using “”. i.e

header('Content-Disposition: attachment; filename="'.$file_name.'"');

instead of

header('Content-Disposition: attachment; filename='.$file_name);

2. If possible replace spaces and commas (,) with underscores (_)

$file_name = str_replace(array('"', "'", ' ', ','), '_', $file_name);

3. Explicitly tell PHP to override headers by setting optional replace parameter to true.

header('Content-type: application/pdf', true);

Escape from Magic Quotes for Non-Frameworks Programmers

Here is a quick thing to help you fetch clean data from GET POST COOKIE and REQUEST input variables. Of course, you need to rely on something like mysql_real_escape_string before writing this into a database. But a common function like this for the entire Web App will keep the data safe from slashes and helps you code without bothering whether magic_quotes_gpc is ON or OFF.


/**
* Use this function to safely retreive data from GET POST COOKIE and REQUEST super globals
*
* @param String $_key Name of the POST element to be retrieved
* @return String Clean value without any slashes even if magic_quotes_gpc is enabled.
*/
function getFromGpc($_key, $_source='p')
{
$_source = strtolower($_source);

if( $_source == 'p' ):
if( get_magic_quotes_gpc() ) {
return stripslashes($_POST[$_key]);
} else {
return ($_POST[$_key]);
}
elseif( $_source == 'g' ):
if( get_magic_quotes_gpc() ) {
return stripslashes($_GET[$_key]);
} else {
return ($_GET[$_key]);
}
elseif( $_source == 'c' ):
if( get_magic_quotes_gpc() ) {
return stripslashes($_COOKIE[$_key]);
} else {
return ($_COOKIE[$_key]);
}
elseif( $_source == 'r' ):
if( get_magic_quotes_gpc() ) {
return stripslashes($_REQUEST[$_key]);
} else {
return ($_REQUEST[$_key]);
}
else:
if( get_magic_quotes_gpc() ) {
return stripslashes($_REQUEST[$_key]);
} else {
return ($_REQUEST[$_key]);
}
endif;
}

Setting Upload Max Size via .htaccess

Here is an example to allow File Uploads upto 2 GB. You may also have to consider Max Execution Time.

PHP4:


<IfModule mod_php4.c>

php_value upload_max_filesize 2G

php_value post_max_size 2G

</IfModule>

PHP5:


<IfModule mod_php5.c>

php_value upload_max_filesize 2G

php_value post_max_size 2G

</IfModule>