title: php: forward ntlm credentials to curl
body: <p>I have a dynamic php page which I need to call with a get parameter. I then want to put the generated html into a string and use it later ( I'm tryign out tonic framework for web services)</p>
  
  <p>So this is similar to <a href="https://stackoverflow.com/questions/1245438/php-read-dynamically-generated-and-echoed-html-into-a-string">PHP - Read dynamically generated (and echoed) HTML into a string?</a> and I tried the answer that uses cURL. </p>
  
  <p>The issue is that authentication is done with ntlm (apache mod_auth_sspi). The php script executing curl is already authenticated, eg only valid users can ever execute it. It is somehow possible to pass on these "credentials" to cURL?
  (username is available but of course not the password)</p>
  
  <p>Or a completely different approach would be fine too but only idea I had was to make a function that creates a string with html content.</p>
  
  <pre><code>$response = new Response($request);
  $format = $request-&gt;mostAcceptable(array(
      'json', 'html', 'txt'
          ));
  
  switch ($format) {
  
      case 'html':
          $response-&gt;addHeader('Content-type', 'text/html');
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL, 'http://localhost/viewRecord.php?identifier=' . $identifier);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM); 
          $html = curl_exec($ch);
          curl_close($ch);
          $response-&gt;body = $html;
          break;
      //...   
  }
  </code></pre>