Is it possible to specify the MIME type of a PHP file as application/javascript
? I have a PHP file that outputs some JavaScript. When strict MIME type checking is enabled, the browser reports an error:
"Refused to execute script from *.php' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled."
Adding this to the PHP file doesn't help:
header("Content-type: application/javascript");
Here is my code:
<?
header('Content-Type: application/javascript');
include ("../admin/config.php");
include ("../custom_functions.php");
?>
var availableTags = ["BBCD"
<?
$prods=decode_prods();
foreach($prods as $key=>$val){
?>
, "
<?
$prods[$key][name] = preg_replace("/(\015\012)|(\015)|(\012)/","",$prods[$key][name]);
trim($prods[$key][name]);
$prods[$key][name]= str_replace("&", "and", $prods[$key][name]);
$prods[$key][name]= str_replace('"', '', $prods[$key][name]);
echo $prods[$key][name];
?>
"
<? } ?>
];
I tried adding this to .htaccess
after reading this post - but it didn't help.
<Files /js/auto.php>
AddType application/javascript .js
</Files>
Click Content Settings. Click the MIME tab in the form. Edit the default content-type, content-language, and character set values as necessary. Optional: If necessary, select File extensions are case sensitive to distinguish between uppercase and lowercase letters when comparing file extensions.
PHP | mime_content_type() function. The mime_content_type() function is an inbuilt function in PHP which is used to get the MIME content-type of a file. Parameters: This function accepts single parameter $file which specifies the path of the file which MIME details to be find.
MIME (Multipurpose Internet Mail Extensions) type is a standard way of describing a data type in the body of an HTTP message or email. The MIME type is passed in the Content-Type header. For example, the Content-Type: text/html header tells the browser that it received an HTML page.
you mean something like that?
header('Content-Type: application/javascript');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With