PHP cURL post fields not working correctly -
it great if help me out please. have far. when run , echo dom contents, i'm still met login page. can't see doing wrong.
$target_url = "https://secretsales.com/"; $fields = array('email' => 'abc', 'password' => '123'); $postfields = http_build_query($fields, '', '&'); // create curl request $target_url $ch = curl_init(); curl_setopt($ch, curlopt_useragent, $useragent); curl_setopt($ch, curlopt_url, $target_url); curl_setopt($ch, curlopt_failonerror, true); curl_setopt($ch, curlopt_followlocation, true); curl_setopt($ch, curlopt_autoreferer, true); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_timeout, 10); curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields, $postfields); curl_setopt($ch, curlopt_ssl_verifypeer, false); $html = curl_exec($ch); // parse html domdocument $dom = new domdocument(); @$dom -> loadhtml($html); // grab on page $xpath = new domxpath($dom); echo $dom->savehtml();
add this:
curl_setopt ($ch, curlopt_cookiejar, dirname(__file__) . "/tmp/cookies.txt"); curl_setopt ($ch, curlopt_cookiefile, dirname(__file__) . "/tmp/cookies.txt");
this stores cookie directory specifed maybe might have create directory.
php post curl http-post
No comments:
Post a Comment