如何使用php curl为特定的ip设置主机名 [英] How to set hostname using php curl for a specific ip

查看:313
本文介绍了如何使用php curl为特定的ip设置主机名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有一个服务器,其上设置了几个虚拟主机。

Hi I have a server which has several virtual hosts set up on it.

我想使用php对这个服务器的ip进行curl请求。
同时我想把这个请求发送到服务器ip上的特定主机名。

I wanted to make a curl request to this server's ip using php. Also I wanted to make this request to a specific hostname on the server's ip.

有办法吗?

更详细的说明:
我想使用内部LAN在我的服务器之间使用其内部IP进行卷曲请求。问题是,我有几个网站托管在此服务器上。所以当我做一个curl请求服务器的内部IP ..像(curl_init(xxx.xxx.xxx.xxx)),我想要能够告诉apache去一个特定的文件夹指向一个虚拟主机。我希望这个问题更清楚.. - Vishesh Joshi 3分钟前编辑

A bit more elaboration : I want to make a curl requests between my servers using internal LAN, using their internal IP. The issue is that I have several sites hosted on this server. So when i make a curl request to the internal IP of the server.. something like (curl_init(xxx.xxx.xxx.xxx)), I want to be able to be tell apache to go to a particular folder pointed to by a virtual host. I hope that made the question a bit more clear.. – Vishesh Joshi 3 mins ago edit

推荐答案

您可以设置主机头在curl请求中:

You can set the host header in the curl request:

<?php
$ch = curl_init('XXX.XXX.XXX.XXX');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: subdomain.hostname.com'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo curl_exec($ch);

这篇关于如何使用php curl为特定的ip设置主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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