易祺專業清潔 為客戶打造最優質的環境 | 快清辦公桌吧 辦公室細菌量比廁所高400倍! |
[php] CURL post and cookie example |
房東:jeff 發表時間:2012-07-18 |
/* |
|
廣利不動產-板橋在地生根最實在--新板特區指名度最高、值得您信賴的好房仲 完整房訊,房屋、店面熱門精選物件,廣利不動產 優質仲介,房屋租賃、買賣資訊透明,交易真安心! 廣利不動產-新板特區指名度最高、值得您信賴的好房仲 您的托付,廣利用心為您服務 |
1 樓住戶:jeff 發表時間:2012-07-18 |
# Define target page $target = "http://www.schrenk.com/nostarch/webbots/cookie_authentication/index.php"; # Define the login form data $form_data="enter=Enter&username=webbot&password=sp1der3"; # Create the cURL session $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $target); // Define target site curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Return page in string curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); // Tell cURL where to write cookies curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt"); // Tell cURL which cookies to send curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $form_data); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); // Follow redirects # Execute the PHP/CURL session and echo the downloaded page $page = curl_exec($ch); echo $page; # Close the cURL session curl_close($ch); ?> Query Session 認證 # Define target page $target = "http://www.schrenk.com/nostarch/webbots/basic_authentication/index.php"; # Define login credentials for this page $credentials = "webbot:sp1der3"; # Create the cURL session $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $target); // Define target site curl_setopt($ch, CURLOPT_USERPWD, $credentials); // Send credentials curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Return page in string # Echo page $page = curl_exec($ch); // Place web page into a string echo $page; // Echo downloaded page # Close the cURL session curl_close($ch); ?> # Include libraries include("LIB_http.php"); include("LIB_parse.php"); # Request the login page $domain = "http://www.schrenk.com/"; $target = $domain."nostarch/webbots/query_authentication"; $page_array = http_get($target, $ref=""); echo $page_array['FILE']; // Display the login page sleep(2); // Include small delay between page fetches echo " "; # Send the query authentication form $login = $domain."nostarch/webbots/query_authentication/index.php"; $data_array['enter'] = "Enter"; $data_array['username'] = "webbot"; $data_array['password'] = "sp1der3"; $page_array = http_post_form($login, $ref=$target, $data_array); echo $page_array['FILE']; // Display first page after login page sleep(2); // Include small delay between page fetches echo " "; # Parse session variable $session = return_between($page_array['FILE'], "session=", "\"", EXCL); # Request subsequent pages using the session variable $page2 = $target . "/index2.php?session=".$session; $page_array = http_get($page2, $ref=""); echo $page_array['FILE']; // Display page two ?> |
2 樓住戶:阿凱 發表時間:2012-07-19 |
/* STEP 1. let’s create a cookie file */ $ckfile = tempnam ("/tmp", "CURLCOOKIE"); /* STEP 2. visit the homepage to set the cookie properly */ $ch = curl_init ("http://somedomain.com/"); curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec ($ch); /* STEP 3. visit cookiepage.php */ $ch = curl_init ("http://somedomain.com/cookiepage.php"); curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec ($ch); /* here you can do whatever you want with $output */ ?> |
姓名: | |||
佈告內容: | |||
其他選項: | |||
|