PHP Guru - need your help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • qw12er
    Confirmed User
    • Apr 2004
    • 799

    #1

    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 !
    I have nothing to advertise ... yet.
  • qw12er
    Confirmed User
    • Apr 2004
    • 799

    #2
    bump 8 char
    I have nothing to advertise ... yet.

    Comment

    • CyR
      Registered User
      • Sep 2002
      • 50

      #3
      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 >_<

      Comment

      • qw12er
        Confirmed User
        • Apr 2004
        • 799

        #4
        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 ...
        I have nothing to advertise ... yet.

        Comment

        • GrouchyAdmin
          Now choke yourself!
          • Apr 2006
          • 12085

          #5
          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);

          Comment

          • GrouchyAdmin
            Now choke yourself!
            • Apr 2006
            • 12085

            #6
            Originally posted by qw12er
            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.

            Comment

            • qw12er
              Confirmed User
              • Apr 2004
              • 799

              #7
              Thanks ! Does the job perfectly !
              I have nothing to advertise ... yet.

              Comment

              Working...