0

It would be great if someone could help me out with this please. This is what I have so far. When I run this and echo the dom contents, I'm still met with the login page. But I can't see what I am doing wrong.

    $target_url = "https://secretsales.com/";
    $fields = array('email' => 'abc', 'password' => '123');
    $postFields = http_build_query($fields, '', '&');

    // make the cURL request to $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 the html into a DOMDocument
    $dom = new DOMDocument();
    @$dom -> loadHTML($html);

    // grab all the on the page
    $xpath = new DOMXPath($dom);

    echo $dom->saveHTML();
  • 3
    I can only guess here, but i would think that site needs to set up a cookie before you can log in. There could also be other security checks in place like xsrf tokens. – scones Feb 09 '13 at 15:10

1 Answers1

0

Add this:

curl_setopt ($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . "/tmp/cookies.txt");
curl_setopt ($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . "/tmp/cookies.txt");

This stores the cookie to a directory as specifed so maybe you might have to create that directory.

Javier Brooklyn
  • 624
  • 3
  • 9
  • 25