title: Validate custom HTTP header in PHP which sent by iOS
body: <p>What I'm trying to do is, sending a HTTP request with custom header from my iOS application to my localhost which runs XAMPP in my MAC machine. Then there is a PHP page which check my particular header and respond according to that.</p>
  
  <p>Following is the iOS part</p>
  
  <pre><code>NSString *urlStr = @"http://127.0.0.1/restapi/index.php?name=anuja";
  
  NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  
  [request setURL:[NSURL URLWithString:urlStr]];
  
  [request setHTTPMethod:@"GET"];
  
  [request addValue:@"apiuser" forHTTPHeaderField:@"X-USERNAME"];
  
  NSLog(@"%s - %d # allHTTPHeaderFields = %@", __PRETTY_FUNCTION__, __LINE__, [request allHTTPHeaderFields]);
  
  NSURLResponse *response;
  NSError *error;
  
  NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:&amp;error];
  
  NSString *responseStr = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  NSLog(@"%s - %d # responseStr = %@", __PRETTY_FUNCTION__, __LINE__, responseStr);
  </code></pre>
  
  <p>And following is the way I'm checking that particular header from my PHP script</p>
  
  <pre><code>        if (isset($_GET["name"])) {
  
              foreach (headers_list() as $name =&gt; $value) {
  
                  if (strcmp($value, "X-USERNAME: apiuser") == 0) {
  
                      $name = $_GET["name"];
  
                      $result = json_encode(array('name' =&gt; $name), JSON_FORCE_OBJECT);
  
                      sendResponse(200, json_encode($result));
  
                      return true;
                  }
              }
  
              sendResponse(203, 'Non-Authoritative Information');
              return false;
          }
  </code></pre>
  
  <p>I'm always getting "Non-Authoritative Information" as response. But I need to get the response with my name which is in 200 status code.</p>
  
  <p>As far as I can understand the problem is with the way I checked the HTTP header inside my PHP script</p>
  
  <pre><code>if (strcmp($value, "X-USERNAME: apiuser") == 0)
  </code></pre>
  
  <p>May be that is not the standard way to check header values and compare it with a pre defined string value in PHP. Is there any way to print the HTTP request header which it receives from PHP side?</p>