I have a simple form saved in a MySQL table on website A.
我有一个简单的表单保存在网站A的MySQL表中。
I need to be able to post that same form on websites B, C, D, E... etc. None of these websites are hosted on the same server as website A. When the form is updated, the form on the rest of the websites must also update.
我需要能够在网站B,C,D,E等上发布相同的表格。这些网站都不会与网站A在同一台服务器上托管。当表格更新时,表格上的其余部分网站也必须更新。
I've tried creating a page on website A which queries the database and displays the form. Then on website B, including the page. I get the following error:
我尝试在网站A上创建一个查询数据库并显示表单的页面。然后在网站B上,包括页面。我收到以下错误:
Warning: include(): http:// wrapper is disabled in the server configuration by allow_url_include=0
警告:include():http://在服务器配置中通过allow_url_include = 0禁用包装器
I know that allow_url_include is probably turned off by most webhosts, so I need a way to circumvent this and safely include my form. Is the solution to use AJAX or Javascript? Could you give pointers on how to accomplish this?
我知道allow_url_include可能被大多数webhosts关闭了,所以我需要一种方法来绕过这个并安全地包含我的表单。是使用AJAX还是Javascript的解决方案?你能指点一下如何做到这一点吗?
3 个解决方案
#1
0
First of all AJAX is done by using javascript, so if you use AJAX you'll be using javascript.
首先,使用javascript完成AJAX,所以如果你使用AJAX,你将使用javascript。
Then, there's no way to do this by embedding the form directly in the html. What I would suggest is:
然后,通过直接在html中嵌入表单,无法做到这一点。我建议的是:
- Create a web service that returns the list of fields that you want to include in your form.
- Create a js script that builds the form dynamically based on the info returned by the service.
- Create function in your web service that receives the information from the form or try to submit the form directly to the url you want (I don't remember if that would work)
- Use that script in all of your pages.
创建一个Web服务,该服务返回要包含在表单中的字段列表。
创建一个js脚本,根据服务返回的信息动态构建表单。
在您的Web服务中创建从表单接收信息或尝试将表单直接提交到您想要的URL的功能(我不记得是否可行)
在所有页面中使用该脚本。
Hope it helps.
希望能帮助到你。
#2
1
If your form lives in a MySQL database, then it's not accurate to say it is "saved on website A". Whatever server-side code you have in website A probably connects to the MySQL database on localhost port 3306 to retrieve the form.
如果您的表单存在于MySQL数据库中,那么说它“保存在网站A上”并不准确。无论您在网站A中使用哪种服务器端代码,都可能连接到localhost端口3306上的MySQL数据库以检索表单。
Code from websites B-E can also connect to MySQL on port 3306 of Server A, if that port is open and there is a MySQL user that can connect remotely. If all servers are in the same private network, that's probably ok. If not, it is a security risk to open the MySQL port to the world. You could limit connections to port 3306 on Server A to only Servers B-E using a firewall. Or, you could write a simple web service on Server A, that when called via HTTP fetches the form from MySQL and returns the form HTML, which you could call asynchronously from Servers B-E.
来自网站B-E的代码也可以在服务器A的端口3306上连接到MySQL,如果该端口是打开的并且有一个可以远程连接的MySQL用户。如果所有服务器都在同一个专用网络中,那可能没问题。如果不是,那么向世界开放MySQL端口是一种安全风险。您可以使用防火墙将服务器A上的端口3306的连接限制为仅限服务器B-E。或者,您可以在服务器A上编写一个简单的Web服务,当通过HTTP调用时从MySQL获取表单并返回表单HTML,您可以从服务器B-E异步调用该表单。
#3
-1
U can use the following ways, u will need to learn them as this is not the place to write a tutorial:
你可以使用以下方法,你需要学习它们,因为这不是编写教程的地方:
- use curl/file_get_contents to get the HTML using on the server side.
- use
<script>
tags on the client side to include a file from the server you host the form - use Iframe
使用curl / file_get_contents在服务器端使用HTML。
在客户端使用
#1
0
First of all AJAX is done by using javascript, so if you use AJAX you'll be using javascript.
首先,使用javascript完成AJAX,所以如果你使用AJAX,你将使用javascript。
Then, there's no way to do this by embedding the form directly in the html. What I would suggest is:
然后,通过直接在html中嵌入表单,无法做到这一点。我建议的是:
- Create a web service that returns the list of fields that you want to include in your form.
- Create a js script that builds the form dynamically based on the info returned by the service.
- Create function in your web service that receives the information from the form or try to submit the form directly to the url you want (I don't remember if that would work)
- Use that script in all of your pages.
创建一个Web服务,该服务返回要包含在表单中的字段列表。
创建一个js脚本,根据服务返回的信息动态构建表单。
在您的Web服务中创建从表单接收信息或尝试将表单直接提交到您想要的URL的功能(我不记得是否可行)
在所有页面中使用该脚本。
Hope it helps.
希望能帮助到你。
#2
1
If your form lives in a MySQL database, then it's not accurate to say it is "saved on website A". Whatever server-side code you have in website A probably connects to the MySQL database on localhost port 3306 to retrieve the form.
如果您的表单存在于MySQL数据库中,那么说它“保存在网站A上”并不准确。无论您在网站A中使用哪种服务器端代码,都可能连接到localhost端口3306上的MySQL数据库以检索表单。
Code from websites B-E can also connect to MySQL on port 3306 of Server A, if that port is open and there is a MySQL user that can connect remotely. If all servers are in the same private network, that's probably ok. If not, it is a security risk to open the MySQL port to the world. You could limit connections to port 3306 on Server A to only Servers B-E using a firewall. Or, you could write a simple web service on Server A, that when called via HTTP fetches the form from MySQL and returns the form HTML, which you could call asynchronously from Servers B-E.
来自网站B-E的代码也可以在服务器A的端口3306上连接到MySQL,如果该端口是打开的并且有一个可以远程连接的MySQL用户。如果所有服务器都在同一个专用网络中,那可能没问题。如果不是,那么向世界开放MySQL端口是一种安全风险。您可以使用防火墙将服务器A上的端口3306的连接限制为仅限服务器B-E。或者,您可以在服务器A上编写一个简单的Web服务,当通过HTTP调用时从MySQL获取表单并返回表单HTML,您可以从服务器B-E异步调用该表单。
#3
-1
U can use the following ways, u will need to learn them as this is not the place to write a tutorial:
你可以使用以下方法,你需要学习它们,因为这不是编写教程的地方:
- use curl/file_get_contents to get the HTML using on the server side.
- use
<script>
tags on the client side to include a file from the server you host the form - use Iframe
使用curl / file_get_contents在服务器端使用HTML。
在客户端使用