title: Retrieving HTML content from a page requiring authentication using PHP
body: <p>I am trying to prototype a PHP script which can extract data from an HTML page. So far it works fine with html pages which don't require authentication. But how can I retrieve content from a page which requires a user to log in first?</p>
  
  <p>Below is my current code:
  </p>
  
  <pre><code>&lt;?php
   $url="http://anandtech.com";
   $html = file_get_contents($url);
   $doc = new DOMDocument();
   @$doc-&gt;loadHTML($html);
   $xml=simplexml_import_dom($doc);
   $items = $xml-&gt;xpath("/html/body/section[@class='content']/section[@class='main_cont']/div[@class='pipeline']/div[@class='pipeline_cont']/ul[1]/li[@class='hide_resp']/a[1]/span[text()]");
   echo '&lt;ul&gt;';
   foreach ($items as $item) {
     echo '&lt;li&gt;' . $item . '&lt;/li&gt;';
   }
   echo '&lt;/ul&gt;';
  ?&gt;
  </code></pre>