简体   繁体   English

使用php在外部使用javascript加载文件

[英]Load a file with javascript externally using php

I have one file named ad.php. 我有一个名为ad.php的文件。 In this file i load some ads from external pages. 在此文件中,我从外部页面加载了一些广告。

(ad.php) : (ad.php)

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

And one file named: (index.php) . 还有一个文件名为: (index.php)

I want to load the contents of the file ad.php finished and then spend it in the index.php file. 我要完成加载ad.php文件的内容,然后将其花费在index.php文件中。

I don't want, that the user loads the javascript files. 我不希望用户加载javascript文件。

i tried some ways: 我尝试了一些方法:

  • file_get_contents file_get_contents
  • curl 卷曲

But the javascript files were loaded in the index.php by the user. 但是,JavaScript文件已由用户加载到index.php中。 Is it possible to load the ad.php externally using php? 是否可以使用php从外部加载ad.php?

If you change your php.ini and set 如果您更改php.ini并设置

allow_url_include = 1      
allow_url_fopen = 1 

you can use include(" http://example.com/ad.php ") 您可以使用include(“ http://example.com/ad.php ”)
this would be the best way if you don't want to use JS. 如果您不想使用JS,这将是最好的方法。
If you want to use JS you could use XMLHttpRequests 如果要使用JS,可以使用XMLHttpRequests

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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