Hi There I have added a virtual host in my windows Host file like this.
192.192.192.192 www.domain.com
I made some php curl request and it is working fine on my local but when I try on my live domain. There I don't understand where to add Virtual host. It is Windows Server. I know there is something in PHP curl. Anyone help how to send host IP and domain in PHP curl. Here is my working code on local machine.
$crul = curl_init();
curl_setopt($crul, CURLOPT_HEADER, false);
curl_setopt($crul, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($crul, CURLOPT_RETURNTRANSFER, true);
curl_setopt($crul, CURLOPT_URL, 'http://www.domain.com'); // where ruquest send
curl_setopt($crul, CURLOPT_POST, true);
curl_setopt($crul, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($crul, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($crul);
Related
Needing information about the goDaddy server error, I used CURL with the following commands in PHP.
I already tested it on another hosting server and it returned me successfully.
I'm using an API for sending messages in whatsapp, everything works: locally and on another server, except on goDaddy.
$endpoint = "https://site...";
$curl = curl_init($endpoint);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER , true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $dados);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, true);
$executa_api= curl_exec($curl);
curl_close($curl);
$retorno= json_decode($executa_api);
do I need to authenticate something to use third-party API in godaddy?
My phpinfo():
Hi I have a server which has several virtual hosts set up on it.
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.
Is there a way to do it?
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
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);
For HTTPS sites use CURLOPT_RESOLVE which exists in every PHP version since PHP 5.5.
<?php
$ch = curl_init('https://www.example.com/');
// note: array used here
curl_setopt($ch, CURLOPT_RESOLVE, array(
"www.example.com:443:172.16.1.1",
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$result = curl_exec($ch);
Sample output:
* Added www.example.com:443:172.16.1.1 to DNS cache
* Hostname www.example.com was found in DNS cache
* Trying 172.16.1.1...
Base on Leigh Simpson,
It works, but I need query string attach with it.
That's what I work around:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://xxx.xxx.xxx.xxx/index.php?page=api&action=getdifficulty");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: subdomain.hostname.com'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo curl_exec($ch);
?>
cURL + proxy noob here, having a hard time. I'm having trouble trying to retrieve a web page from a remote secure server via a proxy. Everything has apparently been set up correctly by a remote dev, such that the following command line instruction works and returns what we're looking for:
curl -k --socks5-hostname localhost:xxxx https://hostname/
However, the following PHP does not echo the requested webpage. Instead it echoes the error 'Couldn't resolve host name':
$proxy = 'localhost:xxxx';
$url = 'https://hostname/';
//$proxyauth = 'user:password';
$ch = curl_init();
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_URL, $url);
$curl_scraped_page = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
if ($error)
echo $error;
elseif ($curl_scraped_page)
echo $curl_scraped_page;
If the $url is changed to a public page, such as Google, the request is successful and everyone is happy.
The connection requires an SSH tunnel if that changes anything at all. The tunnel is open and functioning, as proven by the command line request succeeding.
Is there something obvious that is being missed here?
You need to set option CURLOPT_PROXYTYPE to CURLPROXY_SOCKS5_HOSTNAME, which sadly wasn't defined in old PHP versions, circa pre-5.6; if you have earlier in but you can explicitly use its value, which is equal to 7:
curl_setopt($ch, CURLOPT_PROXYTYPE, 7);
In the option CURLOPT_PROXYTYPE you need to set CURLPROXY_SOCKS5_HOSTNAME option instead of CURLPROXY_SOCKS5.
In this case, the DNS query (for hostname resolving) will be sent to SOCKS proxy and not resolved in the local network.
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);
This constant available since PHP 5.5.23 and PHP 5.6.7 and cURL 7.18.0, so you can simply use it.
Hi I have a server which has several virtual hosts set up on it.
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.
Is there a way to do it?
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
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);
For HTTPS sites use CURLOPT_RESOLVE which exists in every PHP version since PHP 5.5.
<?php
$ch = curl_init('https://www.example.com/');
// note: array used here
curl_setopt($ch, CURLOPT_RESOLVE, array(
"www.example.com:443:172.16.1.1",
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$result = curl_exec($ch);
Sample output:
* Added www.example.com:443:172.16.1.1 to DNS cache
* Hostname www.example.com was found in DNS cache
* Trying 172.16.1.1...
Base on Leigh Simpson,
It works, but I need query string attach with it.
That's what I work around:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://xxx.xxx.xxx.xxx/index.php?page=api&action=getdifficulty");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: subdomain.hostname.com'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo curl_exec($ch);
?>
I was trying to use URL command (CGI script) of a security IP camera from PHP script. The
The php script is hosted in Bluehost server. I checked the cURL version and other stuff , all appears ok. The URL command works on web browser but not in this script??
Thanks for support!
<?php
$url = "http://80.101.186.XX:8372/cgi-bin/viewer/recall.cgi?recall=5AB";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt ($ch, CURLOPT_PORT , 8372);
curl_setopt ($ch, CURLOPT_TIMEOUT , 300);
curl_setopt($ch, CURLOPT_USERPWD, "XXXXX:XXXXXX");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>
Solved it! As #AndrewR said, it is to do with webhost ( bluehost ) blocking non-standard ports. I purchased dedicated IP and requested to open required ports then all worked. Thanks all for help.