The retrieve and read an external URL is easy with PHP. For this purpose, you need only the extension CURL, which is almost always enabled by default. Even if the server is behind a proxy that is not a problem.

You can Agent strings and so transmit certain data even faking referrer and user. Only cookies are slightly more complex, I’m going to open its own theme.

With the following function you can easily transfer data from an external URL with PHP and CURL read.

function getData ($ url) {
$ ch = curl_init ();
curl_setopt ($ ch, CURLOPT_URL, $ url);
curl_setopt ($ ch, CURLOPT_HEADER, 0); Transmitted // Header, Boolean
curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); // Return data

        // Proxy configuration:
curl_setopt ($ ch, CURLOPT_PROXYAUTH, CURLAUTH_NTLM);
curl_setopt ($ ch, CURLOPT_PROXY, 'proxy.example.com:8080');
curl_setopt ($ ch, CURLOPT_PROXYPORT, 8080);
curl_setopt ($ ch, CURLOPT_PROXYUSERPWD, 'username: password');

        // Referer and User Agent
curl_setopt ($ ch, CURLOPT_REFERER, 'http://example.com');
curl_setopt ($ ch, CURLOPT_USERAGENT, 'Chrome / Safari ... Whatever');

curl_setopt ($ ch, CURLOPT_TIMEOUT, 20);
curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, 20);

$ result = curl_exec ($ ch);
$ info = curl_getinfo ($ ch);
$ error = curl_error ($ ch);

curl_close ($ ch);

return $ result; // Returns the result, but you can also Info or Error output
}

If you do not need the proxy commenting on the section in the PHP function made easy.Just as you can the header on or off (true / false or 1/0). Also the user agent or referrer you can simply comment out if you do not want to use him explicitly.

Now you can with the function getData (URL) via simple PHP and CURL with Proxy, User Agent and Referrer read and process the external URL.

Comments


The retrieve and read an external URL is easy with PHP. For this purpose, you need only the extension...

Read Post

The retrieve and read an external URL is easy with PHP. For this purpose, you need only the extension...

Read Post

Leave a Reply

Your email address will not be published. Required fields are marked *