Hướng dẫn curl login php session - curl đăng nhập phiên php

Hôm nay hà minh giới thiệu với các bạn làm thế nào curl được login của môt trang web bất kỳ và xử lý được dự liệu trong ấy như thế nào.

Nội dung chính

  • Acknowledgments
  • 1 – Update your Facebook status
  • 2 – Get download speed of your webserver
  • 3 – Myspace login using cURL
  • 4 – Publish a post on your WordPress blog, using cURL
  • 5 – Test the existence of a given url
  • 8 – Get feed subscribers count in full text
  • 9 – Get the content of a webpage into a PHP variable
  • 10 – Post to Twitter using PHP and cURL

chúng ta bắt đầu nào

để thực hành được lệnh curl trong máy tính của chúng ta, việc đầu tiên chúng ta là bật curl trong php lên.

ví dụ tôi xử dụng xampp thì đường dẫn nó là thế này.

/xampp/php/php.ini các bạn ctr+f và gõ từ curl để bật curl lên như thế này "extension=php_curl.dll"

khởi động lại apache để tiến hành curl localhost nhé các bạn.

//khởi tạo curl $ch = curl_init();
$ch = curl_init();

//làm việc với đường dẫn curl_setopt($ch, CURLOPT_URL, 'http://www.code.elite.vn/');
curl_setopt($ch, CURLOPT_URL, 'http://www.code.elite.vn/');

//cho xem curl các trình duyệt curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36');
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36');

//làm việc curl  post dự liệu curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POST, true);

//tải dự liệu tên và mật khẩu curl_setopt($ch, CURLOPT_POSTFIELDS, "username=xxx&password=xxx");
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=xxx&password=xxx");

//trích xuất dự liệu curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//cho phép curl cookie và session curl_setopt($ch, CURLOPT_COOKIESESSION, true);  curl_setopt($ch, CURLOPT_COOKIEFILE  , dirname(__FILE__).'/cookie.txt');  curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt'); $answer = curl_exec($ch);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
 curl_setopt($ch, CURLOPT_COOKIEFILE  , dirname(__FILE__).'/cookie.txt');
 curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt');
$answer = curl_exec($ch);

curl_setopt($ch, CURLOPT_URL, 'http://www.code.elite.vn/'); curl_setopt($ch, CURLOPT_POST, false); curl_setopt($ch, CURLOPT_POSTFIELDS, ""); $answer = curl_exec($ch); if ($answer ($ch)) {     echo "bạn đã cập nhật vào trang code.elite.vn thành công" }
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, "");
$answer = curl_exec($ch);
if ($answer ($ch)) {
    echo "bạn đã cập nhật vào trang code.elite.vn thành công"
}

quá ví dụ này hà minh hy vọng các bạn hiểu được một phần nào với curl để áp dụng vào công việc của các bạn, nếu có gì chưa hiểu các bạn để tin nhắn ở phía dưới, hà minh cố gắng sẽ giúp các bạn.

i want to login a web site with curl php an i can it but no active login and when i call another php file for request this site I see that no avtive login I want save login information for use it in the other php file but iam not slove it.

a.php:

this code is ok and i can login site but when call b.php login session is lose

=====================

b.php:

I want to do when call a.php and login to site when call b.php it is work ok and not lose login seesion ( a.php )

asked Jun 30, 2019 at 19:23Jun 30, 2019 at 19:23

2

a.php should at least contain:

$cookies = tempnam('/tmp','cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies); 

b.php should at least contain:

$cookies = tempnam('/tmp','cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);

CURLOPT_COOKIEJAR is the path where curl will write the cookies from the http response.

CURLOPT_COOKIEFILE is the path where curl will read the cookies for the http request.

answered Jun 30, 2019 at 20:29Jun 30, 2019 at 20:29

Hướng dẫn curl login php session - curl đăng nhập phiên php

François HuppéFrançois HuppéFrançois Huppé

1,9161 gold badge5 silver badges15 bronze badges1 gold badge5 silver badges15 bronze badges

0

cURL, and its PHP extension libcURL, are tools which can be used to simulate a web browser. In fact, it can for example, submit forms. In this article, I’m going to show you 10 incredible things that you can do using PHP and cURL.

Acknowledgments

New to cURL? If yes, check out the following articles to learn the purposes and basics of cURL/libcurl. If yes, check out the following articles to learn the purposes and basics of cURL/libcurl.

  • cURL Wikipedia page
  • cURL tutorial: Using cURL to automate HTTP jobs

Please note that some of the techniques shown here can be used for “blackhat” methods. The goal of this article is only educationnal, please do not use any of the snippets below for illegal stuff.

1 – Update your Facebook status

Wanna update your facebook status, but don’t want to go to facebook.com, login, and finally being able to update your status? Simply save the following code on your server, define the variables, and voilà!

'.ucfirst($first_name).'/', $page, $form_id);
curl_setopt($ch, CURLOPT_POSTFIELDS,'post_form_id='.$form_id[1].'&status='.urlencode($status).'&update=Update');
curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/home.php');
curl_exec($ch);
?>

2 – Get download speed of your webserver

Do you ever wanted to know the exact download speed of your webserver (or any other?) If yes, you’ll love that code. You just have to initialize the $url variable with any resources from the webserver (images, pdf, etc), place the file on your server and point your browser to it. The output will be a full report of download speed.

 $value)
{
	printf("%-30s %s\n", $label, $value);
}
?>

Source: http://cowburn.info/2008/11/29/download-speed-php-curl http://cowburn.info/2008/11/29/download-speed-php-curl

3 – Myspace login using cURL

4 – Publish a post on your WordPress blog, using cURL

Source: http://www.seo-blackhat.com/article/myspace-login-function-php-curl.html http://www.seo-blackhat.com/article/myspace-login-function-php-curl.html

4 – Publish a post on your WordPress blog, using cURL

5 – Test the existence of a given url
This function can post on your WordPress blog. You don’t need to login to your WP dashboard etc.
Though, you must activate the XMLRPC posting option in your WordPress blog. If this option isn’t activated, the code will not be able to insert anything into WordPress database. Another thing, make sure the XMLRPC functions are activated on your php.ini file.

function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$category,$keywords='',$encoding='UTF-8')
{
    $title = htmlentities($title,ENT_NOQUOTES,$encoding);
    $keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);
     
    $content = array(
        'title'=>$title,
        'description'=>$body,
        'mt_allow_comments'=>0,  // 1 to allow comments
        'mt_allow_pings'=>0,  // 1 to allow trackbacks
        'post_type'=>'post',
        'mt_keywords'=>$keywords,
        'categories'=>array($category)
    );
    $params = array(0,$username,$password,$content,true);
    $request = xmlrpc_encode_request('metaWeblog.newPost',$params);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
    curl_setopt($ch, CURLOPT_URL, $rpcurl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 1);
    $results = curl_exec($ch);
    curl_close($ch);
    return $results; 
?>

5 - Kiểm tra sự tồn tại của một url nhất định

Tôi biết, nó nghe có vẻ cơ bản. Trên thực tế, & nbsp; nó là cơ bản, nhưng nó cũng rất hữu ích, đặc biệt là khi bạn phải làm việc với các tài nguyên bên ngoài.

Nguồn: & nbsp; http: //www.phpsnippets.info/test-existence-of-a-given-url-with-curl http://www.phpsnippets.info/test-existence-of-a-given-url-with-curl

Trong một bài viết trước, & nbsp; tôi đã thảo luận về cách những kẻ gửi thư rác gửi thư từ blog WordPress của bạn. Để làm như vậy, họ chỉ cần điền vào mảng Postfields $ với thông tin họ muốn hiển thị và tải trang. Tất nhiên, mã này chỉ dành cho mục đích giáo dục.
Of course, this code is only for educationnal purposes.

Source: http://www.catswhocode.com/blog/how-spammers-spams-your-blog-comments http://www.catswhocode.com/blog/how-spammers-spams-your-blog-comments

Hầu hết các blogger sử dụng AdSense trên blog của họ và (cố gắng) kiếm tiền với Google. Đoạn trích xuất sắc này cho phép bạn theo dõi thu nhập adsense của bạn với trình đọc RSS! Chắc chắn là tuyệt vời. .
(Script too big to be displayed on the blog, click here to preview)
Source: http://planetozh.com/blog/my-projects/track-adsense-earnings-in-rss-feed/

8 - Nhận số người đăng ký nguồn cấp dữ liệu được tính bằng văn bản đầy đủ

Nếu bạn là một blogger, bạn có thể sử dụng dịch vụ Feedburner phổ biến, điều này làm bạn biết có bao nhiêu người lấy nguồn cấp dữ liệu RSS của bạn. Feedburner có một con gà con để tự hào hiển thị số lượng thuê bao của bạn trên blog của bạn. Cá nhân tôi thích vẻ ngoài của Chicklet, nhưng tôi đã nghe rất nhiều blogger phàn nàn về nó. Happilly, Curl có thể chỉ cần lấy giá trị đếm và trả lại cho bạn như một biến để bạn có thể hiển thị nó như bạn muốn trên blog của mình.

//get cool feedburner count
$whaturl="https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=feedburner-id";

//Initialize the Curl session
$ch = curl_init();

//Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//Set the URL
curl_setopt($ch, CURLOPT_URL, $whaturl);

//Execute the fetch
$data = curl_exec($ch);

//Close the connection
curl_close($ch);
$xml = new SimpleXMLElement($data);
$fb = $xml->feed->entry['circulation'];
//end get cool feedburner count

Source: http://www.hongkiat.com/blog/display-google-feed-subscriber-count-in-text/ http://www.hongkiat.com/blog/display-google-feed-subscriber-count-in-text/

9 - Nhận nội dung của một trang web vào một biến PHP

Đây là một điều rất cơ bản để làm với Curl, nhưng với những khả năng vô tận. Khi bạn có một trang web trong biến PHP, ví dụ, bạn có thể truy xuất một thông tin cụ thể trên trang để sử dụng trên trang web của riêng bạn.

10 - Đăng lên Twitter bằng Php và Curl

Twitter rất phổ biến kể từ một thời gian và có lẽ bạn đã có một tài khoản ở đó. .

$cookies = tempnam('/tmp','cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
0

Source: http://morethanseven.net/2007/01/20/posting-to-twitter-using-php/ http://morethanseven.net/2007/01/20/posting-to-twitter-using-php/