使用php从外部加载javascript文件

I have one file named ad.php. In this file i load some ads from external pages.

(ad.php):

<script type='text/javascript' src='www.example.org'></script>...

And one file named: (index.php).

I want to load the contents of the file ad.php finished and then spend it in the index.php file.

I don't want, that the user loads the javascript files.

i tried some ways:

  • file_get_contents
  • curl

But the javascript files were loaded in the index.php by the user. Is it possible to load the ad.php externally using php?

If you change your php.ini and set

allow_url_include = 1      
allow_url_fopen = 1 

you can use include("http://example.com/ad.php")
this would be the best way if you don't want to use JS.
If you want to use JS you could use XMLHttpRequests