使用参数调用位于另一台服务器中的PHP文件,并读取另一台服务器PHP中的变量值 [英] Call PHP file located in another server with parameter and read variable values in another server PHP
问题描述
在B服务器.php文件中包含A服务器.php文件,并从A服务器Php文件获取变量值
include A server .php file in B server .php file and get variable values from A server Php File
我正在尝试调用位于与RPG(Report Program Generator,AS400)连接的另一台服务器中的PHP文件.我想从我的Web服务器上调用该PHP文件,并希望可以访问变量和函数.
I'm trying to call PHP file which is located in another server which is connected with RPG(Report Program Generator, AS400). I would like to call that PHP file from my web server and would like to have access to variable and functions.
我尝试了包含"但不起作用
I tried Include but not working
我想用参数调用RPG端的.PHP文件.
I would like to call .PHP file which in RPG side with parameter.
A.php
<?php
include("http://10.1.1.12/a/file.php?email=aaa@a.com&name=abc");
echo $a; //values from file.php
?>
file.php
<?php
$email = $_REQUEST['email'];
$name = $_REQUEST['name'];
$a = "testing";
echo $a;
?>
推荐答案
出于安全原因,默认情况下在php.ini中禁用了使用 include
来获取另一台服务器的响应的方法,很可能您不会这样做.不能使用它.改用 file_get_contents
.
Getting the response of another server using include
is disabled by default in the php.ini for security reasons, most likely you won’t be able to use it. Use file_get_contents
instead.
在您的 file.php
中,您可以使用数据进行json响应并回显它:
In your file.php
you can make a json response using your data and echo it:
<?php
$email = $_REQUEST['email'];
$name = $_REQUEST['name'];
$a = "testing";
header('Content-type: application/json');
echo json_encode(
'email' => $email,
'name' => $name,
'a' => $a
);
?>
在 A.php
中,您需要解析json字符串以获取数据:
And in the A.php
you need to parse the json string to get your data:
<?php
$data = json_decode(file_get_contents('http://10.1.1.12/a/file.php?email=aaa@a.com&name=abc'));
echo $data['email'], ' ', $data['name'], ' ', $data['a'];
?>
这篇关于使用参数调用位于另一台服务器中的PHP文件,并读取另一台服务器PHP中的变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!