简体   繁体   中英

Load a file with javascript externally using php

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM