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. Show
Nội dung chính
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(); //làm việc với đường dẫn 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'); //làm việc curl post dự liệu 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"); //trích xuất dự liệu 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_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" } 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:
b.php should at least contain:
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 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. AcknowledgmentsNew 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.
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 statusWanna 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 webserverDo 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 cURL4 – Publish a post on your WordPress blog, using cURLSource: 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 cURL5 – Test the existence of a given url 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 địnhTô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. 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. . 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à CurlTwitter rất phổ biến kể từ một thời gian và có lẽ bạn đã có một tài khoản ở đó. . 0Source: http://morethanseven.net/2007/01/20/posting-to-twitter-using-php/ http://morethanseven.net/2007/01/20/posting-to-twitter-using-php/ |