maximviper
BANNED
- Oct 25, 2010
- 338
- 87
Hello .
i was wondering if anyone could guide me a bit about how to extract hidden form fields while login or form posting.
he problem is ,as those fields are dynamic so i have to extract them on fly before setting CURLOPT_POSTFIELDS .
i tried to save the whole html page in a text file with he following :
$fp = fopen('form.html', 'w');
curl_setopt($ch, CURLOPT_FILE, $fp);
but that doesnt help. bcos i m not able to reopen the file. i ave no idea.
Is it possible to store $ch data into a buffer variable so that i wont have to save the whole webpage and reopen again ?
postdata is inform of :
Also CURLOPT_FOLLOWLOCATION always trows error bcos of something related to safe mode .i coudnt figured out a solution yet
i was wondering if anyone could guide me a bit about how to extract hidden form fields while login or form posting.
he problem is ,as those fields are dynamic so i have to extract them on fly before setting CURLOPT_POSTFIELDS .
i tried to save the whole html page in a text file with he following :
$fp = fopen('form.html', 'w');
curl_setopt($ch, CURLOPT_FILE, $fp);
but that doesnt help. bcos i m not able to reopen the file. i ave no idea.
PHP:
function curl_post($site,$postdata){
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 5.1; rv:2.0b11) Gecko/20100101 Firefox/4.0b11");
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
curl_setopt($ch, CURLOPT_URL, $site);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); // excluded bcos it throws error about safe mode
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_POST, TRUE);
//saving html page to file on server . this part works
$fp = fopen('inbox.html', 'w');
curl_setopt($ch, CURLOPT_FILE, $fp);
fclose($fp);
//opening the file . not works
$fh = fopen('inbox.html', 'r');
if($fh)
{
echo "file not opened";
}
else
{
echo "file opened";
}
echo "filesize = ".filesize($myFile);
$theData = fread($fh, filesize($myFile));
fclose($fh);
echo $theData;
//for extracting toekn .no use for now
// $regex = '/token="(.+?)">/';
// preg_match($regex,$data,$match);
// $str=$match[1];
// echo $str;
//curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); //postdata will be modified according to token extracting. no need unless i extract token
$response = curl_exec ($ch); // execute the curl command
}
postdata is inform of :
Code:
title=$title&FCKeditor1=$article&access=private&vtok=68d6e4f4be9eab2409cb57469370950d&submitted=Posting+Blog...Please+Wait...