title: CURL HTTP Authentication at server side
body: <p>I am building a web service with Zend and i have to authenticate the users before sending them response. The user will send a request to a server page, using curl, passing his credentials in the form of <code>curl_setopt($curl, CURLOPT_USERPWD, 'key:pass')</code>;</p>
  
  <p>Iam using Zend framework and so the server side page is denoted like:</p>
  
  <p><a href="http://www.example.com/app_name/public/controller/action/parameter">http://www.example.com/app_name/public/controller/action/parameter</a></p>
  
  <p>Here is the total code for user's request (client.php):</p>
  
  <pre><code>&lt;?php
  $curl = curl_init('http://www.example.com/app/public/user/add/1');
  
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);                         
  curl_setopt($curl, CURLOPT_USERPWD, 'username:password');
  curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);                    
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);                          
  curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);                           
  curl_setopt($curl, CURLOPT_USERAGENT, 'Sample Code');
  
  $response = curl_exec($curl);                                          
  $resultStatus = curl_getinfo($curl);                                   
  
  if($resultStatus['http_code'] == 200) {
      echo $response;
  } else {
      echo 'Call Failed '.print_r($resultStatus);                         
  }
  
  ?&gt;
  </code></pre>
  
  <p>Now what i want is that, i must be able to retrieve the username and password at the server side (in my zend controller), so that i can verify the user credentials from database and send the response accordingly. So how can i do authentication in another page?</p>