获取客户端curl服务器的servername

时间:2015-01-17 16:20:49

标签: php apache curl

以下脚本在名为domain_one.com的服务器上运行。

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'https://domain_two.com/testing/curl2.php');
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,array('x'=>1,'y'=>2,'z'=>3));
$result = curl_exec($ch);
curl_close($ch);
print_r($result);

curl2.php位于domain_two.com,并具有以下脚本:

echo('<pre>'.print_r($_POST,1).'</pre>');
echo('<pre>'.print_r($_SERVER,1).'</pre>');

当我在domain_one.com上运行第一个脚本时,我得到以下输出。

Array
(
    [x] => 1
    [y] => 2
    [z] => 3
)

Array
(
    [HTTPS] => on
    [SSL_TLS_SNI] => domain_two.com
    [HTTP_HOST] => domain_two.com
    [HTTP_ACCEPT] => */*
    [CONTENT_LENGTH] => 319
    [HTTP_EXPECT] => 100-continue
    [CONTENT_TYPE] => multipart/form-data; boundary=----------------------------ed367d0bca2b
    [PATH] => /sbin:/usr/sbin:/bin:/usr/bin
    [SERVER_SIGNATURE] => Apache/2.2.15 (CentOS) Server at domain_two.com Port 443

    [SERVER_SOFTWARE] => Apache/2.2.15 (CentOS)
    [SERVER_NAME] => domain_two.com
    [SERVER_ADDR] => 222.222.222.222
    [SERVER_PORT] => 443
    [REMOTE_ADDR] => 111.111.111.111
    [DOCUMENT_ROOT] => /var/www/domain_two/html
    [SERVER_ADMIN] => root@localhost
    [SCRIPT_FILENAME] => /var/www/domain_two/html/testing/curl2.php
    [REMOTE_PORT] => 43092
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => POST
    [QUERY_STRING] => 
    [REQUEST_URI] => /testing/curl2.php
    [SCRIPT_NAME] => /testing/curl2.php
    [PHP_SELF] => /testing/curl2.php
    [REQUEST_TIME_FLOAT] => 1421509992.179
    [REQUEST_TIME] => 1421509992
)

domain_two.com上的脚本是否可以获取正在访问它的服务器名称(即domain_one.com)?我看到我可以获得与domain_one.com相关联的REMOTE_ADDR(即111.111.111.111)。

如果两个脚本都作为子域(即subdomain.domain_one.com)访问,会有什么影响?

我为什么这样做: domain_one向domain_two脚本发送curl请求。 domain_two设置一些标头并响应它收到请求,但不退出。相反,它会执行一些漫长的过程(一分钟左右,可能更长),当它完成时,需要向domain_one发送一个curl请求,指示它已完成。

0 个答案:

没有答案