GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   PHP Guru - need your help (https://gfy.com/showthread.php?t=777935)

qw12er 10-19-2007 07:22 PM

PHP Guru - need your help
 
How can I force an HTTP GET request through a proxy server with PHP ?

Right now I use this function to send my info :
function myPost($URL, $script, $data){

$sock = fsockopen($URL, 80, $errno, $errstr);
fputs($sock, "GET ".$script." HTTP/1.0\r\n");
fputs($sock, "Host:".$URL."\r\n");
fputs($sock, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($sock, "Content-length: " . strlen($data) . "\r\n");
fputs($sock, "Accept: */*\r\n");
fputs($sock, "\r\n");
fputs($sock, "$data\r\n");
fputs($sock, "\r\n");
fclose($sock);
}

Thanks for any help !

qw12er 10-19-2007 10:43 PM

bump 8 char

CyR 10-19-2007 11:23 PM

fputs($sock, "Host:".$URL.":8080\r\n");

Missing port ? Other than that I can't see much wrong, although I'm tired and can't think straight atm >_<

qw12er 10-19-2007 11:30 PM

no the function is working fine but it's not going through a proxy as it is.

I guess my question should be more like how do you interact with a proxy in php. Can't find much doc on this subject ...

GrouchyAdmin 10-19-2007 11:30 PM

Here, I'll save you some time. Rewrite for cURL. It'll save you many, many, many headaches.

Code:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $requestUrl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 'timeout_in_seconds');
    curl_setopt($ch, CURLOPT_PROXY, 'proxy_ip:proxy_port');
    $data = curl_exec($ch);
    curl_close($ch);


GrouchyAdmin 10-19-2007 11:36 PM

Quote:

Originally Posted by qw12er (Post 13261740)
I guess my question should be more like how do you interact with a proxy in php. Can't find much doc on this subject ...

See my following answer. Writing fsock code to do posting is both deprecated, and painful. Trying to make it nest multiple levels for proxy CONNECT statements, et al, is just asinine when there already exists the functionality.

qw12er 10-20-2007 12:12 AM

Thanks ! Does the job perfectly !


All times are GMT -7. The time now is 07:47 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123