我有两台服务器:
1。许可
2。供应
现在客户端(android / ios设备)向许可证服务器发送请求。所以我们从 GET 中获取了一些参数,我将其转发到Provisioning服务器,使用 CURL ,如下所示:
$skey = $this->input->get('site_id');
$uid = $this->input->get('user_id');
$url = "http://127.0.0.1/example.com?site_key=".$skey."&uid=".$uid;
$wget_cmd = "wget --no-check-certificate \"".$url."\" >/dev/null 2>/dev/null ";
//echo($wget_cmd);
//exec($wget_cmd);
// create a new cURL resource
$ch = curl_init();
//curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and pass it to the browser
curl_exec($ch);
echo curl_error($ch);
// close cURL resource, and free up system resources
curl_close($ch);
现在,配置服务器有一个名为 provisioning.php 的文件。在那里,我根据来自许可证服务器的请求执行一些数据库操作,并生成一个我想要发送回许可证服务器的URL。
在配置时,我会根据数据库操作生成这样的URL:
$uri = site_url('/uploads/'.$user_ini['custom_ini_filename'].'.ini');
$ini_url = json_encode($uri,JSON_UNESCAPED_SLASHES);
我希望将此 $ini_url
返回给许可证服务器。
- 我该怎么做?
- 如何在许可证服务器上访问此
醇>$ini_url
?
答案 0 :(得分:1)
将CURLOPT_RETURNTRANSFER设置为1并简单地将curl_exec($ ch)的响应分配给变量:
许可证服务器
$skey = $this->input->get('site_id');
$uid = $this->input->get('user_id');
$url = "http://127.0.0.1/example.com?site_key=".$skey."&uid=".$uid;
$wget_cmd = "wget --no-check-certificate \"".$url."\" >/dev/null 2>/dev/null ";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
curl_setopt($ch, CURLOPT_URL, $url);
// The blow variable stores the response from provision server
$response_from_provision_server = curl_exec($ch);
echo curl_error($ch);
curl_close($ch);
您还需要从配置服务器回显$ ini_url的内容,这是为响应curl_exec()调用而发送回许可证服务器的输出。
配置服务器
$uri = site_url('/uploads/'.$user_ini['custom_ini_filename'].'.ini');
$ini_url = json_encode($uri,JSON_UNESCAPED_SLASHES);
// echo the $ini_url variable
echo $ini_url;