Created
September 4, 2015 04:12
-
-
Save mahedi2014/9137a0490af051bc994f to your computer and use it in GitHub Desktop.
Using curl and fopen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
go=1 (hidden) | |
hp='value from textbox' | |
message='value from texarea' | |
c='captcha image' | |
*/ | |
/**Data generation**/ | |
$vars = array( | |
'go' => '1', | |
'hp' => '4422332211', | |
'message' => 'lllllllllll', | |
'c' => 'VBNM' | |
); | |
$data = http_build_query($vars); | |
/***CURL uses***/ | |
$ch = curl_init(); | |
curl_setopt( $ch, CURLOPT_HEADER, 1); | |
curl_setopt( $ch, CURLINFO_HEADER_OUT, 1); | |
curl_setopt( $ch, CURLOPT_AUTOREFERER, 1); | |
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1); | |
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0); | |
curl_setopt( $ch, CURLOPT_COOKIEJAR, $ckfile); | |
curl_setopt( $ch, CURLOPT_POST, 1); | |
curl_setopt( $ch, CURLOPT_COOKIEFILE, $ckfile); | |
curl_setopt( $ch, CURLOPT_REFERER, $url); | |
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data); | |
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Keep-Alive: 115', 'Connection: keep-alive', 'Content-type: application/x-www-form-urlencoded', 'Content-length: '.strlen($to_post_field))); | |
curl_setopt( $ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1'); | |
curl_setopt( $ch, CURLOPT_URL, $url); | |
$store = curl_exec($ch); | |
/***Fopen uses***/ | |
fwrite($fp, "POST /index.php HTTP/1.1\r\n"); | |
fwrite($fp, "Host: www.example.com\r\n"); | |
fwrite($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); | |
fwrite($fp, "Content-Length: ".strlen($data)."\r\n"); | |
fwrite($fp, "Cookie: PHPSESSID=".$sid."\r\n"); | |
fwrite($fp, "Connection: close\r\n"); | |
fwrite($fp, "\r\n"); | |
fwrite($fp, $data); | |
header('Content-type: text/plain'); | |
while (!feof($fp)) { | |
echo fgets($fp, 1024); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment