Running Javascript in PHP
- by Zero
I'm loading an external .php file using:
<script type="text/javascript" src="myfile.js.php"></script>
Within the external myfile.js.php file, I'm using:
<?php
header('content-type: text/javascript');
$message = "Test message";
?>
document.write('<?php echo $message; ?>');
Everything works fine until I change the name of myfile.js.php to just myfile.php
Why does it stop working if I remove the .js part from the file name? I'm serving the file as text/javascript, plus shouldn't the .js part be ignored since .php is the actual file extension?
Does anyone know why?
Thanks!