0

Lets say i make a HTTP-Request with CURL like this(thanks for this source to thahelper by the way):

REQUEST.PHP

<?PHP
function curlRequest($url,$data)
{
    $fp = fopen("cookie.txt", "w");
    fclose($fp);
    $login = curl_init();
    curl_setopt($login, CURLOPT_COOKIEJAR, "cookie.txt");
    curl_setopt($login, CURLOPT_COOKIEFILE, "cookie.txt");
    curl_setopt($login, CURLOPT_TIMEOUT, 40000);
    curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($login, CURLOPT_URL, $url);
    curl_setopt($login, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($login, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($login, CURLOPT_POST, TRUE);
    curl_setopt($login, CURLOPT_POSTFIELDS, $data);
    ob_start();
    return curl_exec ($login);
    ob_end_clean();
    curl_close ($login);
    unset($login);    
}

$data = array(
    'user' => 'example_user',
    'pass' => 'eXam777plepA'
    );

echo curlRequest("http://example.com/", $data);
?>

Lets assume the request is successfull and i got the site back that you get when you are logged in successfully.(The code works, i tried it already)

How is it possible to get the site http://example.com/my_profile which you also only get if you are logged in correctly? If i make another request i just get a blank page. Thank you.

user3877230
  • 439
  • 1
  • 5
  • 18

1 Answers1

0

Do not close the curl handle after logging in. Do another curl_init and curl_setopt the cookie file and curl_exec to retrieve results.

TurtleTread
  • 1,297
  • 2
  • 12
  • 23