title: ASIHTTPRequest and PHP Status Code always returns 200 or 500
body: <p>My problem is that the php responseStatusCodes are not showing up on iOS. No matter what status code I return in sendResponse(), when reading the responseStatusCode in iOS, I get the output 500. Why is this and how can I fix it? Im assuming this is an error with PHP and has nothing to do with ASIHTTPRequest. But just for good measure, I've included the code used on the iOS side.</p>
  
  <p>Let me know if their is any other code you need to help assist me.</p>
  
  <p>Thanks in advance!</p>
  
  <p>Here is the code I use to start a connection to the server.</p>
  
  <pre><code>ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
  request.shouldAttemptPersistentConnection = NO;
  [request setPostValue:name forKey:@"name"];
  [request setPostValue:email forKey:@"email"];
  [request setPostValue:phash forKey:@"phash"];
  [request setDelegate:self];
  [request startAsynchronous];
  </code></pre>
  
  <p>This is the code that I run when receiving a request finished message.</p>
  
  <pre><code>/
  - (void)requestFinished:(ASIHTTPRequest *)request
  {
      NSLog(@"Request Finished");
      int statusCode = [request responseStatusCode];
      if (statusCode == 150) {
          NSLog(@"User Already Registered.");
      } else if (statusCode == 155){
          NSLog(@"User Not Registered");
      } else if (statusCode == 403) {
          NSLog(@"Tester 2");
      } else if (statusCode == 200) {
          if (registering == true){
          [UIView animateWithDuration:1.0 animations:^{
              _wheel.alpha = 0.0;
          }];
          [UIView animateWithDuration:1.0 delay:1.0 options:0 animations:^{
              _clickToRegister.alpha=1.0;
          }completion:nil];
          } else {
              [UIView animateWithDuration:1.0 animations:^{
                  _wheel.alpha = 0.0;
              }];
              [UIView animateWithDuration:1.0 delay:1.0 options:0 animations:^{
                  _clickToLogin.alpha=1.0;
              }completion:nil];
          }
          NSLog(@"Tester 3");
      } else if (statusCode &gt; 1 &amp;&amp; statusCode &lt; 1000){
          NSLog(@"Test Worked");
          NSLog(@"%d",statusCode);
      } else {
          NSLog(@"%d",statusCode);
          NSLog(@"Tester 4");
      }
  }
  </code></pre>
  
  <p>Here is the PHP Code that is supposed to send a responseStatusCode.</p>
  
  <pre><code>function sendResponse($status, $body = '', $content_type = 'text/html')
  {
      $status_header = 'HTTP/1.1 ' . $status . ' ' . 'error';
      header($status_header);
      header('Content-type: ' . $content_type);
      echo $body;
  }
  </code></pre>
  
  <p>And here is the code that calls this function.</p>
  
  <pre><code>sendResponse(503, 'User not Registered');
  return false;
  </code></pre>
  
  <p>Here is the code for the entire file with the sendResponse call in it.</p>
  
  <pre><code>&lt;?php
  require_once 'includes/main.php';
  class dumb {
  function dumber(){
      echo "Hello, PHP!";
  /*--------------------------------------------------
      Handle visits with a login token. If it is
      valid, log the person in.
  ---------------------------------------------------*/
  
  
  if(isset($_GET['tkn'])){
  
      // Is this a valid login token?
      $user = User::findByToken($_GET['tkn']);
  
      if($user){
  
          // Yes! Login the user and redirect to the protected page.
  
          $user-&gt;login();
          redirect('panic://success');
      }
  
      // Invalid token. Redirect back to the login form.
      redirect('panic://fail');
  }
  
  
  
  /*--------------------------------------------------
      Handle logging out of the system. The logout
      link in protected.php leads here.
  ---------------------------------------------------*/
  
  
  if(isset($_GET['logout'])){
  
      $user = new User();
  
      if($user-&gt;loggedIn()){
          $user-&gt;logout();
      }
  
      redirect('index.php');
  }
  
  
  /*--------------------------------------------------
      Don't show the login page to already 
      logged-in users.
  ---------------------------------------------------*/
  
  
  $user = new User();
  
  if($user-&gt;loggedIn()){
      redirect('protected.php');
  }
  
  
  
  /*--------------------------------------------------
      Handle submitting the login form via AJAX
  ---------------------------------------------------*/
  
          if (isset($_POST["name"]) &amp;&amp; isset($_POST["email"]) &amp;&amp; isset($_POST["phash"])){
              rate_limit($_SERVER['REMOTE_ADDR']);
  
              rate_limit_tick($_SERVER['REMOTE_ADDR'], $_POST['email']);
  
              $message = '';
              $name = $_POST["name"];
              $email = $_POST["email"];
              $phash = $_POST["phash"];
              $subject = 'Your Login Link';
  
              if(!User::exists($email)){
                  $subject = "Thank You for Registering!";
                  $message = "Thank you for registering at our site!\n\n";
                  // Attempt to login or register the person
              $user = User::loginOrRegister($email, $name, $phash);
  
  
              $message.= "You can login from this URL:\n";
              $message.= get_page_url()."?tkn=".$user-&gt;generateToken()."\n\n";
  
              $message.= "The link is going expire automatically after 10 minutes.";
  
              $result = send_email($fromEmail, $_POST['email'], $subject, $message);
  
              if(!$result){
              sendResponse(403, 'Error Sending Email');
              return false;
              }
              }
              else{
                  sendResponse(150, 'User Already Registered');
                  return false;
              }
          }
          else if(isset($_POST["email"]) &amp;&amp; isset($_POST["phash"])){
              rate_limit($_SERVER['REMOTE_ADDR']);
  
              rate_limit_tick($_SERVER['REMOTE_ADDR'], $_POST['email']);
  
              $message = '';
              $name = '';
              $email = $_POST["email"];
              $phash = $_POST["phash"];
              $subject = 'Your Login Link';
  
              if(!User::exists($email)){
                  sendResponse(155, 'User Not Registered');
                  return false;
              }
              else{
              // Attempt to login or register the person
              $user = User::loginOrRegister($email, $name, $phash);
  
  
              $message.= "You can login from this URL:\n";
              $message.= get_page_url()."?tkn=".$user-&gt;generateToken()."\n\n";
  
              $message.= "The link is going expire automatically after 10 minutes.";
  
              $result = send_email($fromEmail, $_POST['email'], $subject, $message);
  
              if(!$result){
              sendResponse(403, 'Error Sending Email');
              return false;
              }
          }
          }
  
          die(json_encode(array(
              'message' =&gt; 'Thank you! We\'ve sent a link to your inbox. Check your spam folder as well.'
          )));
  
  /*--------------------------------------------------
      Output the login form
  ---------------------------------------------------*/
  }
  }
  $api = new dumb;
  $api-&gt;dumber();
  ?&gt;
  </code></pre>