For example, there is an ex.js file that contains the usual alert ("AAA"); This script is called from a remote machine:

<script src="http://192.168.0.1/ex.js"> </script> 

Everything is working. I want this script to be passed to the php script. That is, instead of ex.js, I made exp.php and inserted the following code:

 <?php echo 'alert("AAA");';?> 

However, this does not work. More precisely, it works in the browser, but in the client I need it does not. Comparing the first and second cases in WireShark revealed a difference in the Content-Type. In the working version - application / x-javascript, in the second case text / html.

I want to do this in order to subsequently use some condition, depending on which the necessary JS script will be sent.

  • That is the question is how to install content-type in php? - Skywave
  • Yes, I figured it out. In php, you need to specify at the beginning: Header ("content-type: application / x-javascript"); - toog
  • @Skywave Wanted to know, is it possible to transmit img in the same way? Well, suppose I have a construct: '<script> </ script>' '<img src>' '<script> </ script>' Can I send it all through echo as well? - toog
  • Any request can be proxied through pkhp and files too. Any. (well, or almost any)) - Skywave
  • @Skywave How can I transfer 2 different JS scripts using one php file? those. I need to pass 2 constructs <script></script> and <script></script> separately. - toog

1 answer 1

In exp.php you need to specify at the beginning:

 Header("content-type: application/x-javascript");