Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- #
- # M.S.I. Angel Cantu Jauregui
- # angel.cantu [a] sie-group.net
- # http://www.sie-group.net
- #
- # obtiene datos por socket, segun peticion POST o GET
- # data = array( stream, argumentos, datos_post );
- function socket_iodata( $host, $data, $port )
- {
- $r='';
- $http_request = "$data[0] $data[1] HTTP/1.0\r\n";
- $http_request .= "Host: $host\r\n";
- if( !strcmp($data[0], "POST") ) # si es post
- {
- if( $data[3] && !strcmp($data[3], "json") ) # datos json
- $http_request .= "Content-Type: application/json;\r\n";
- else
- $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
- $http_request .= "Content-Length: " . strlen($data[2]) . "\r\n";
- }
- #$http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
- # $http_request .= "Connection: keep-alive\r\n";
- $http_request .= "\r\n";
- if( !strcmp($data[0], "POST") ) # si es post
- $http_request .= $data[2];
- if( !strcmp($port, "443") )
- $fullhost= 'ssl://'. $host;
- else $fullhost= $host;
- if( ($fs = @fsockopen($fullhost, $port, $errno, $errstr, 10))==FALSE )
- {
- echo 'No se puede abrir socket :: ['. $errno. '] '. $errstr;
- }
- else
- {
- fwrite($fs, $http_request);
- while ( !feof($fs) )
- $r .= fgets($fs, 1160); // One TCP-IP packet
- fclose($fs);
- $r= explode("\r\n\r\n", $r, 2);
- return $r;
- }
- }
- # obtiene datos por socket, segun peticion POST o GET
- # data = array( stream, argumentos, datos_post );
- function curl_iodata( $host, $data, $port )
- {
- $r='';
- $curl= curl_init($host.$data[1]); # inciamos url
- curl_setopt( $curl, CURLOPT_CUSTOMREQUEST, $data[0] );
- curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
- if( !strcmp($data[0], "POST") ) # si es post
- {
- curl_setopt( $curl, CURLOPT_POSTFIELDS, $data[2] );
- if( $data[3] && !strcmp($data[3], "json") ) # datos json
- $contenido= array( 'Content-Type: application/json', 'Content-Length: '. strlen($data[2]));
- else $contenido= array( 'Content-Type: application/x-www-form-urlencoded', 'Content-Length: '. strlen($data[2]));
- curl_setopt( $curl, CURLOPT_HTTPHEADER, $contenido );
- curl_setopt( $curl, CURLOPT_POST, 1 );
- }
- $r= curl_exec($curl);
- curl_close($curl);
- return $r;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement