Autor | Zpráva | ||
---|---|---|---|
Korči Profil * |
#1 · Zasláno: 29. 8. 2012, 15:04:04
Ahoj všem,
potřeboval bych udělat parazitní skript, kterej sám pošle POST data na jinej skript. Prostě by udělal to, co dělá normální HTML-formulář. Umí todle PHP? Našel jsem jenom funkci http_post_data, ale to asi nebude ono. Věděl byste prosím někdo? Děkuju moc. |
||
Ugo Profil |
#2 · Zasláno: 29. 8. 2012, 16:56:44
zkus tuhle fci.
function send_post($url, $data,$referer='') { // Convert the data array into URL Parameters like a=b&foo=bar etc. if(is_array($data)) { $data = http_build_query($data); } // parse the given URL //$all_url=$url; $url = parse_url($url); // extract host and path: $host = $url['host']; $all_url=$host; $path = @$url['path']; if(empty($url['scheme'])) $url['scheme']="http"; if(strtoupper($url['scheme'])=="HTTP") { $port=80; } elseif(strtoupper($url['scheme'])=="HTTPS") { $port=443; $all_url="ssl://".$host; } // open a socket connection on port 80 - timeout: 30 sec $fp = fsockopen($all_url, $port, $errno, $errstr, 30); if ($fp){ // send the request headers: fputs($fp, "POST $path HTTP/1.1\r\n"); fputs($fp, "Host: $host\r\n"); if ($referer != '') fputs($fp, "Referer: $referer\r\n"); fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); fputs($fp, "Content-length: ". strlen($data) ."\r\n"); fputs($fp, "Connection: close\r\n\r\n"); fputs($fp, $data); $result = ''; while(!feof($fp)) { // receive the results of the request $result .= fgets($fp, 128); } } else { return array( 'status' => 'err', 'error' => "$errstr ($errno)" ); } // close the socket connection: fclose($fp); // split the result header from the content $result = explode("\r\n\r\n", $result, 2); $header = isset($result[0]) ? $result[0] : ''; $content = isset($result[1]) ? $result[1] : ''; // return as structured array: return array( 'status' => 'ok', 'header' => $header, 'content' => $content ); } |
||
Keeehi Profil |
#3 · Zasláno: 29. 8. 2012, 18:40:37
Korči:
„Umí todle PHP?“ Umí. Já nejraději pracuji s cURL, ale dá se to udělat i jinak. Třeba přes file_get_contents(). $postdata = http_build_query( array( 'var1' => 'some content', 'var2' => 'doh' ) ); $opts = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata ) ); $context = stream_context_create($opts); $result = file_get_contents('http://example.com/submit.php', false, $context); |
||
Časová prodleva: 12 let
|
0