使用包括包含php代码的跨域 - 失败 [英] using includes cross domain that contain php code - failing

查看:320
本文介绍了使用包括包含php代码的跨域 - 失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列网站,所有网站都托管在具有不同域的同一服务器上。我想要托管一些常见的PHP scrips,然后可以从其他域名调用这些。



我有一个新鲜的php so pls excuse代码尝试 - 我已经尝试了以下的迭代,可以尝试并帮助您了解我的目标!



从php标签...

  include('http://www.mydomain/common_include.php?show_section = $ section'); 






  $ show_section = $ _GET ['show_section']; 
include('http://www.mydomain/common_include.php'); //然后$ show_section将可用于包含的文件/ cod






最后,我试图在include中包含一个函数,然后尝试从父脚本运行include。 p>


  • 我更喜欢保持这个PHP
    的方向而不是让
    涉及服务器(文件
    系统等(但我可以更改
    权限等)

  • 我可以,但不希望只是将同一个库分别上传到每个域

  • 我理解PHP是在服务器上运行的,因此可能会有问题将脚本包含到另一个服务器上。







EDIT
OK OK - 我得到它的坏习惯,所以不会做它....谢谢你对于快速答案。
然而,有没有任何其他建议如何显示这个基本的php应用程序在所有的网站,没有必要添加到每个网站的根的文件?只是为了防止大量的脚本复制...(从数据库或任何其他soloutions大声呼唤脚本)
再次感谢您的帮助

解决方案

如果你可以将远程PHP文件包含到你自己的项目中,这将是一个巨大的安全风险。在服务器将其发送给您之前解析PHP,因此跨域包含将仅包含脚本生成的输出。包含PHP文件以便可以执行的唯一方法是通过本地文件系统。



如果你看一下PHP.net的关于include的文档,你可以找到: / p>


如果在PHP中启用了URL fopen wrappers(它们处于默认配置),则可以指定要包含的文件一个URL(通过HTTP或其他支持的包装器 - 参见协议列表的支持协议/包装器列表),而不是本地路径名。如果目标服务器将目标文件解释为PHP代码,则可以使用与HTTP GET一起使用的URL请求字符串将变量传递到包含的文件。这不严格说与包含文件和让它继承父文件的变量范围相同;该脚本实际上正在远程服务器上运行,然后将结果包括在本地脚本中。


这完全解释了整个事情。


I have a series of web sites all hosted on the same server with different domains. I want to host some common PHP scrips and then be able to call these from the other domains.

Im am a bit fresh with my php so pls excuse code attempts - I have tried iterations of the following which may try and help you understand what I am aiming for!

from within php tags ...

include('http://www.mydomain/common_include.php?show_section=$section');


$show_section = $_GET['show_section'];
include('http://www.mydomain/common_include.php');//Then $show_section would be available to the included file/cod


Finally I have tried pulling in the include which contains a function then trying to run that include from the parent script.

  • I would much prefer to keep this PHP orientated rather than getting involved with the server (file systems etc (but I can change permissions etc)
  • I can but would prefer not to just upload the same library to each of the domains separately
  • I understand PHP is run on the server hence maybe problematic to include scripts across onto another server.

Thanks in advance.

#

EDIT OK OK - I get that its bad practice so will not do it....THANKS VERY MUCH FOR THE QUICK ANSWERS. However is there any other recommendations of how to esentially show this basic php app on all of the sites with out haveing to add the files to the root of each site? Just to prevent massive script duplication...(thinking out loud call the scripts in from a db or anyother soloutions) Again thanks for your assistance

解决方案

That would be a huge security risk if you could just include remote PHP files to your own projects. The PHP gets parsed before the server sends it to you so cross-domain includes would only contain the output the script generates. The only way to include PHP files so that they can be executed is via local filesystem.

If you look at PHP.net's documentation about include, you can find this:

If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be included using a URL (via HTTP or other supported wrapper - see List of Supported Protocols/Wrappers for a list of protocols) instead of a local pathname. If the target server interprets the target file as PHP code, variables may be passed to the included file using a URL request string as used with HTTP GET. This is not strictly speaking the same thing as including the file and having it inherit the parent file's variable scope; the script is actually being run on the remote server and the result is then being included into the local script.

Which pretty much explains the whole thing.

这篇关于使用包括包含php代码的跨域 - 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆