如何阅读网站的数据并发布到另一个网站的数据库,如mysql

时间:2015-04-06 09:19:27

标签: php curl mysqli https http-headers

以下代码我有3个功能,当我运行我的example2网站时,它就像提供用户名和密码后进入我的网站。示例2工作正常。但是在example1网站上,当我执行这个程序时,它进入我以前的页面,它应该没有用户名和密码的影响。在这两种情况下,我都得到用户名和&通过运行httpfox软件将密码加上其他数据作为$ data变量。我估计,在示例2中,该软件显示所有信息,例如'用户名= YYYYY&密码= YYYYYYYYY& remember = yes& submit =登录& action = do_login& url = http%3A%2F%2Fwww.hackforums.net% 2Findex.php&安培; my_post_key = 876890b33b8b9260ba3acfc1998b1594'但是在example1中,它只显示,'用户名= XXXXX&密码= XXXXXXXXXXXXXXXXXXXXX' 任何人都可以知道答案吗?这将是很大的帮助!

另一个问题是它没有运行任何' https'网站。你知道怎么做吗。非常感谢!



<html>
<body>
 
<?php 
       
       
	login("http://www.example1.com:9080/mrportal/loginaction", "username=XXXXX&password=XXXXXXXXXXXXXXXXXXXXX") ; 
echo grabpage("http://www.example1.com:9080/mrportal/");

login("http://www.example2.net/member.php", "username=YYYYY&password=YYYYYYYYY&remember=yes&submit=Login&action=do_login&url=http%3A%2F%2Fwww.hackforums.net%2Findex.php&my_post_key=876890b33b8b9260ba3acfc1998b1594") ; 
echo grabpage("http://www.example2.net)

	function login($url, $data)
	{
	  $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_TIMEOUT,40000);
	  curl_setopt($login,CURLOPT_RETURNTRANSFER,true);
	  curl_setopt($login,CURLOPT_URL, $url);
	  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();
	  return curl_exec($login);
	  ob_end_clean();
	  curl_close($login);
	  unset($login);  
	}
	
	function grabpage($site)
	{
	  $ch = curl_init();
	  curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
	  curl_setopt($ch,CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
	  curl_setopt($ch,CURLOPT_TIMEOUT,400);
	  curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
	  curl_setopt($ch,CURLOPT_URL, $site);
	  ob_start();
	  return curl_exec($ch);
	  ob_end_clean();
	  curl_close($ch);
	 }
 
 
    function post_data($site, $data)
	{
	  
	  $datapost = curl_init();
	  $headers = array("Expect:");
	  curl_setopt($datapost,CURLOPT_URL, $site);
	  curl_setopt($datapost,CURLOPT_TIMEOUT,40000);	 
	  curl_setopt($datapost, CURLOPT_HEADER, TRUE);
	  curl_setopt($datapost, CURLOPT_HTTPHEADER, $headers);
	  curl_setopt($datapost,CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
	  curl_setopt($datapost,CURLOPT_POST, TRUE);
	  curl_setopt($datapost,CURLOPT_POSTFIELDS, $data);
	  curl_setopt($datapost, CURLOPT_COOKIEFILE, "cookie.txt");
	  ob_start();
	  return curl_exec($datapost);
	  ob_end_clean();
	  curl_close($datapost);
	  unset($datapost);  
	}
 ?>

</body>
</html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

尝试使用:

curl_setopt($login, CURLOPT_SSL_VERIFYPEER, false);
在您的代码中

跳过https地址的ssl验证。