Login to ASP website before using PHP Simple HTML

2019-05-14 21:55发布

问题:

I am using "PHP Simple HTML DOM Parser" to parse data from a gaming ASP website. The data that i need to grab are only visible to registered users so i need something to log me in to site before start using it. Can someone suggest me a script or something which it can do this ? Thanks a lot in advance!

回答1:

First, you should post with:

<?php
function do_post_request($url, $data, $optional_headers = null)
{
  $params = array('http' => array(
              'method' => 'POST',
              'content' => $data
            ));
  if ($optional_headers !== null) {
    $params['http']['header'] = $optional_headers;
  }
  $ctx = stream_context_create($params);
  $fp = @fopen($url, 'rb', false, $ctx);
  if (!$fp) {
    throw new Exception("Problem with $url, $php_errormsg");
  }
  $response = @stream_get_contents($fp);
  if ($response === false) {
    throw new Exception("Problem reading data from $url, $php_errormsg");
  }
  return $response;
}

That should be able to send a post request. After that, you should be able to grab what you need.