Login to cURL

I am using cURL for the first time. I need to go to the site. I have a problem setting my cookie and extracting it, so that I can access this page more than once, but several times. I found the code on the Internet, it takes a long time to get to the site and to “Break the page” for some detailed information. so I just want to know if everything is alright! Belove code (it’s just not ready to enter the code for Scraper)

<?php

curl_login('http://mywantedsite.com/login.php','user=******&pass=******','','off');

echo curl_grab_page('http://mywantedsite.com/somepage.php','','off');

function curl_login($url,$data,$proxy,$proxystatus){
    $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_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
    curl_setopt($login, CURLOPT_TIMEOUT, 40);
    curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE);
    if ($proxystatus == 'on') {
        curl_setopt($login, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($login, CURLOPT_HTTPPROXYTUNNEL, TRUE);
        curl_setopt($login, CURLOPT_PROXY, $proxy);
    }
    curl_setopt($login, CURLOPT_URL, $url);
    curl_setopt($login, CURLOPT_HEADER, TRUE);
    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();      // prevent any output
    return curl_exec ($login); // execute the curl command
    ob_end_clean();  // stop preventing output
    curl_close ($login);
    unset($login);    
}                  

function curl_grab_page($site,$proxy,$proxystatus){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    if ($proxystatus == 'on') {
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
        curl_setopt($ch, CURLOPT_PROXY, $proxy);
    }
    curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
    curl_setopt($ch, CURLOPT_URL, $site);
    ob_start();      // prevent any output
    return curl_exec ($ch); // execute the curl command
    ob_end_clean();  // stop preventing output
    curl_close ($ch);
}  
?>
+3
source share
3 answers

, . . HTTP- HTTP. , , , . . .

+2

$strPostFields ,

$this->m_strResourceCurl = curl_init();

cURL script

curl_setopt( $this->m_strResourceCurl, CURLOPT_POSTFIELDS, $strPostFields );

, .

+1

URL

$login = curl_init($url);
0

Source: https://habr.com/ru/post/1741110/


All Articles