hey everyone!! Is it possible to use file_get_contents via a proxy? If so how? I've been looking online for a loooong time with no luck! Any help wouuld be greatly appreciated! thanks
Try <?php $opts = array('http' => array('proxy' => 'tcp://127.0.0.1:8080', 'request_fulluri' => true)); $context = stream_context_create($opts); $data = file_get_contents('http://www.php.net', false, $context); echo $data; ?> PHP:
try this... $ch = curl_init(); curl_setopt ($ch, CURLOPT_PROXY, $proxy); curl_setopt($ch, CURLOPT_URL, url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); $a = curl_exec($ch); echo $a;
The problem is, the script I already have and run uses file_get_contents.. so it would be much easier to adapt!
create a new function like function my_file_get_contents($url) { //Push your CURL Function here and return the content } Code (markup): and replace all file_get_contents( to my_file_get_contents( I think it will helpful . If you need full script , feel free when ask me.
This is my own function I sometimes use.. just replace "file" in file_get_contents with "curl" to make curl_get_contents You need to get a valid working proxy iport or it will not show any content.
First, read this comment on the PHP manual page. A lot of it is irrelevant, but the proxy stuff is there. http://www.php.net/manual/en/function.file-get-contents.php#58758 Next, jump back to the top of the page and continue by paying special attention to the context argument of the file_geT_contents function. This is going to lead you to the stream_context_create manual page eventually http://www.php.net/manual/en/function.stream-context-create.php Which will in turn lead you to manual pages for all of the options you're going to need for the stream. When all is said and done, it's probably going to be easier, and more effective in the long run, to create a function that uses cURL and then using sed or something to replace all occuranges of file_get_contents in your script to your functions name. You're more than likely going to have to make replacements to add the context argument to all of your existing calls anyways.
I see ok!! Well I'll give the curl function a try with the addition of the missing parameter and see how thins go! thanks