So I was building a site using PHP and Jquery and I found a need to use PHP inside of a Javascript file to get a Javascript to do a certain function based on the users permission info in PHP. Normally I would have made the file a
.php instead of a
.js and injected the php in the Javascript where it needed to be.
This would make the Javascript in the file turn to black text in dreamweaver and including it like this would set the content type to a Javascript file
<script type="text/javascript" src="javascript/custom_functions.php"></script>
As I started to change the file I forgot to remove the
.js from the file name and ended up with
<script type="text/javascript" src="javascript/custom_functions.php.js"></script>
I didn't catch it at first because both PHP and Javascript where working completely fine. This turned the php text to pain black and color coded the file to a Javascript file.
Quick example to test with
// Save this with a .php.js
// test.php.js
// Set the message in php
<?php $message = 'This is my test file!'; ?>
// Alert the php message in Javascript
alert("<?php echo $message; ?>");
-
- // Save this with a .php.js
- // test.php.js
-
- // Set the message in php
- <?php $message = 'This is my test file!'; ?>
-
- // Alert the php message in Javascript
- alert("<?php echo $message; ?>");
-
-
So this also works the other way I've found out
test.js.php dreamweaver colors it to php instead. So I knew you can't execute PHP in a
.js file. which is why this caught me off guard and why I usually use a php file for the instances like this.
though neat I still reverted the code to how I would normally do it but the question I find going through my head is would this double extension naming convention break down over time due to updates in php or is this something that is common practice and will remain?
Since I've not worked with doing double extensions and cannot find anything about them besides uploading them I bring the question here.