Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I disable DNS lookup in PHP? I have the IP address and host name
    primarykey
    data
    text
    <p>We have mirrors of a website using the same domain name but different IP addresses - it's used for caching worldwide.</p> <p>To check the mirror is working, in theory we can use:</p> <pre><code>$request = new HttpRequest(); ... // IP address of mirror $request-&gt;setUrl('http://xxx.xxx.xxx.xxx'); $request-&gt;setHeaders(array('host' =&gt; 'domainname.com')); ... $request-&gt;send(); </code></pre> <p>But this gives an error saying "'HttpRequestException' with message 'Couldn't resolve host name; ..."</p> <p>We already know the IP address and host name, so is there a way to disable the DNS lookup in PHP? Or in the http request headers?</p> <p>Note:</p> <p>I need to login and have cookies, so I can't use ping. Also the website needs to think its the correct domain, which is why I'm using 'Host' in the header.</p> <p>UPDATE 1:</p> <p>Tried replacing HttpRequest with curl but this gives the same error message:</p> <pre><code>$curl = curl_init() ... curl_setopt($curl, CURLOPT_URL, 'http://xxx.xxx.xxx.xxx'); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Host: domainname.com')); ... if (!curl_exec($curl)) { echo curl_error($curl); // Output is 'Couldn't resolve host 'domainname.com' } </code></pre> <p>UPDATE 2:</p> <p>Ah... It looks like its because of a redirect. I also have the following settings</p> <pre><code>curl_setopt($curl, CURLOPT_MAXREDIRS, 10); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); </code></pre> <p>From the command line, this works</p> <pre><code>curl --header "Host: domainname.com" http://xxx.xxx.xxx.xxx </code></pre> <p>But it doesn't when I try to log in</p> <pre><code>curl --header "Host: domainname.com" --location --data "username=username&amp;password=password" http://xxx.xxx.xxx.xxx/login.php </code></pre> <p>I get</p> <pre><code>curl: (6) Couldn't resolve host 'domainname.com' </code></pre> <p>Can I keep the ipaddress + host combination? Or maybe I have to loop through the redirects?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload