1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

fsocketopen via proxy server?

Discussion in 'PHP' started by Squiggs, Apr 8, 2013.

  1. #1
    Hey guys,

    I need to mofidy the following code to communicate via a proxy server, can anyone please advise on how to do this?"

    PHP:
    1. function fetchURL( $url )
    2. {
    3.     $url_parsed = parse_url( $url );
    4.     $host = $url_parsed['host'];
    5.     $port = $url_parsed['port'];
    6.     if ( $port == 0 )
    7.     {
    8.         $port = 80;
    9.     }
    10.     $path = $url_parsed['path'];
    11.     if ( $url_parsed['query'] != "" )
    12.     {
    13.         $path .= "?".$url_parsed['query'];
    14.     }
    15.     $out = "GET ".$path." HTTP/1.0\r\nHost: {$host}\r\n\r\n";
    16.     $fp = @fsockopen( @$host, $port, &$errno, &$errstr, 30 );
    17.     if ( $fp )
    18.     {
    19.         $in = "Unknown";
    20.         return $in;
    21.     }
    22.     fwrite( $fp, $out );
    23.     $body = FALSE;
    24.     while ( !feof( $fp ) )
    25.     {
    26.         $s = fgets( $fp, 1024 );
    27.         if ( $body )
    28.         {
    29.             $in .= $s;
    30.         }
    31.         if ( $s == "\r\n" )
    32.         {
    33.             $body = TRUE;
    34.         }
    35.     }
    36.     fclose( $fp );
    37.     return $in;
    38. }
    Squiggs, Apr 8, 2013 IP
  2. Squiggs

    Squiggs Member

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #2
    Any PHP pro's out there know what I need to change here?
    Squiggs, Apr 8, 2013 IP
  3. gusto

    gusto Member

    Messages:
    103
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #3
    It's very easy. Just change this part:

    $fp=@fsockopen(@$host,$port,&$errno,&$errstr,30)

    With your proxy IP and port and leave the rest of the code as is. It will work.

    gusto, Apr 8, 2013 IP