title: How to get sessionId and viewstate variables from this code?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3820666/grabbing-the-href-attribute-of-an-a-element">Grabbing the href attribute of an A element</a>  </p>
  </blockquote>
  
  
  
  <p>How can I extract the <code>sessionId</code> and <code>viewstate</code> variables from this code?</p>
  
  <p>The code is this:</p>
  
  <pre class="lang-php prettyprint-override"><code>$url = "http://www.atb.bergamo.it/ITA/Default.aspx?SEZ=2&amp;PAG=38&amp;MOD=LINTRV";
  
  $ckfile = tempnam ("/tmp", "CURLCOOKIE");
  $ch = curl_init ($url);
  curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile); 
  curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
  $html = curl_exec ($ch);
  curl_close($ch);
  
  preg_match('~&lt;input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="(.*?)" /&gt;~',$html,$viewstate);
  
  var_dump(file_get_contents($ckfile)); //&lt;--- There's the sessionId variable in it
  var_dump($viewstate[1]);              //&lt;--- View State
  </code></pre>
  
  <p>Can you help me please?</p>