Your location:Tech News>News>Script>[Method] attached demo source PHP implementation login Sohu from advertising ad network data

Latest News

[Method] attached demo source PHP implementation login Sohu from advertising ad network data

Author:fsadmin

Views:

  define ( "SITE_PATH", $ _SERVER [ ''DOCUMENT_ROOT'']);

  require_once SITE_PATH.''/ Class / SimpleHtmlDom.class.php '';

  class GetData {

  private $ url;

  public function __construct () {

  $ This-> url = "http: // union.sogou.com / index.action?searchBean.timeSegment = yestoday ";

  $ This-> LoginUrl = "http: // union.sogou.com / ";

  $ This-> PostData = $ this-> LoginUrl."Loginauth.action ";

  $ This-> table = "dwz_union";

  }

  public function post ($ code)

  {

  $ POST [ ''loginFromPage''] = "homePage";

  $ POST [ ''username''] = "xxxxxx";

  $ POST [ ''password''] = "xxxxx";

  $ POST [ ''activecode''] = $ code;

  $ POST [ ''button.x ''] = "14";

  $ POST [ ''button.y ''] = "16";

  foreach ($ POST as $ key => $ value)

  {

  $ Tmp [] = $ key."=".$ Value;

  }

  $ PostStr = implode ( "&", $ tmp);

  $ Filedir = SITE_PATH."/ TMP / Cookies";

  $ Cookie_file = $ filedir."/ Cookie.TXT";

  $ Result = $ this-> curl ($ this-> PostData, "http: // union.sogou.com / loginauth.action ", $ postStr, $ cookie_file);

  $ Url = "http: // union.sogou.com / index.action ";

  $ PostArr = "searchBean.timeSegment = yestoday ";

  $ Response = $ this-> curl ($ url, "http: // union.sogou.com / index.action?pid = dengwz7788 ", $ postArr, $ cookie_file);

  $ This-> saveData ($ response);

  }

  private function saveData ($ response)

  {

  $ Dom = str_get_html ($ response);

  $ Tmp = $ dom-> find ( ''div.rtable table tbody tr '', 1) -> plaintext;

  $ Data = preg_split ( "/ \ s + / i", $ tmp);

  $ This-> link ();

  $ Date = date ( ''Ym-d'', strtotime ( ''- 1 day''));

  $ Datetime = date ( ''Ymd H: i: s'');

  $ Money = $ data [ ''4''];

  $ Shows = $ data [ ''2''];

  $ Times = $ data [ ''3''];

  $ Sql = "select sum (money) as total from {$ this-> table}";

  $ Query = mysql_query ($ sql);

  $ TotaTmp = mysql_fetch_row ($ query);

  var_dump ($ totalTmp);

  if (empty ($ totaTmp [ ''0'']))

  {

  $ Total = $ money;

  } Else {

  $ Total = $ totaTmp [ ''0''] + $ money;

  }

  $ Sql = "insert into {$ this-> table} (date, datetime, money, shows, times, total) values ( ''{$ date}'', ''{$ datetime}'', ''{$ money}'', '' {$ shows} '','' {$ times} '','' {$ total} '') ";

  mysql_query ($ sql);

  }

  private function link ()

  {

  $ Link = mysql_connect ( ''localhost'', ''root'', '''');

  mysql_select_db ( ''dblog'', $ link);

  mysql_query ( ''SET NAMES utf8'');

  }

  private function saveHtml ($ infomation, $ filedir, $ filename)

  {

  if (!$ This-> mkdirs ($ filedir))

  {

  return 0;

  }

  $ Sf = $ filedir."/".$ Filename;

  $ Fp = fopen ($ sf, "w"); // Open a file for writing

  fwrite ($ fp, $ infomation); // stored content

  fclose ($ fp); // close the file

  }

  //Create a directory

  private function mkdirs ($ dir)

  {

  if (!is_dir ($ dir))

  {

  if (!$ This-> mkdirs (dirname ($ dir))) {

  return false;

  }

  if (!mkdir ($ dir, 0777)) {

  return false;

  }

  }

  return true;

  }

  public function login ()

  {

  $ Filedir = SITE_PATH."/ TMP / Cookies";

  if (!$ This-> mkdirs ($ filedir))

  {

  echo "directory creation failed";

  exit;

  }

  $ Cookie_file = $ filedir."/ Cookie.TXT";

  $ Ch = curl_init ();

  curl_setopt ($ ch, CURLOPT_URL, $ this-> LoginUrl);

  curl_setopt ($ ch, CURLOPT_HEADER, 0); // do not return header portion

  curl_setopt ($ ch, CURLOPT_USERAGENT, "Mozilla / 4.0 (compatible; MSIE 6.0; Windows NT 5.0) ");

  curl_setopt ($ ch, CURLOPT_COOKIEJAR, $ cookie_file);

  // curl_setopt ($ ch, CURLOPT_REFERER, "http: // 125.89.69.234 ");

  curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1);

  curl_setopt ($ ch, CURLOPT_TIMEOUT, "10");

  $ Response = curl_exec ($ ch);

  curl_close ($ ch);

  // draw Su Wei Mei Yun Qin CURL

  }

  private function curl ($ url, $ url2, $ fields, $ cookie_file)

  {

  $ Ch = curl_init ();

  curl_setopt ($ ch, CURLOPT_URL, $ url);

  curl_setopt ($ ch, CURLOPT_HEADER, 0); // do not return header portion

  curl_setopt ($ ch, CURLOPT_USERAGENT, "Mozilla / 4.0 (compatible; MSIE 6.0; Windows NT 5.0) ");

  curl_setopt ($ ch, CURLOPT_POST, 1);

  curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ fields);

  curl_setopt ($ ch, CURLOPT_COOKIEFILE, $ cookie_file);

  curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1);

  curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1);

  curl_setopt ($ ch, CURLOPT_HTTPHEADER, array ( "Host: union.sogou.com "));

  curl_setopt ($ ch, CURLOPT_REFERER, $ url2);

  $ Response = curl_exec ($ ch);

  // echo curl_error ($ ch);

  curl_close ($ ch);

  return $ response;

  }

  }

  $ GetData = new GetData ();

  if (isset ($ _ POST [ ''code'']))

  {

  $ GetData-> POST ($ _ POST [ ''code'']);

  }

Recommend article

Relate article