最新消息: 新版网站上线了!!!

php模拟登录

  1. $url = "http://www.myurl.com/login.php"
  2. $username="myuser"
  3. $password="mypassword"
  4. $loginfields = "username=$username&password=$password"
  5. $useragent="Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"; 
  6. $ch = curl_init(); 
  7. //you might need to set some cookie details up (depending on the site) 
  8. curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); 
  9. curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt"); 
  10.  
  11. curl_setopt($ch, CURLOPT_USERAGENT, $useragent); //set our user agent 
  12. curl_setopt($ch, CURLOPT_POST, 1); //set how many paramaters to post 
  13. curl_setopt($ch, CURLOPT_URL,$url); //set the url we want to use 
  14. curl_setopt($ch, CURLOPT_POSTFIELDS,$loginfields); //set the user_name field to 'joeyjohns' 
  15.  
  16. $result= curl_exec ($ch); //execute and get the results 
  17. curl_close ($ch); 
  18. print $result//display the reuslt 

 

转载请注明:谷谷点程序 » php模拟登录