Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8782195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:30:45+00:00 2026-06-13T20:30:45+00:00

I am trying to send a username and password from an iOS app using

  • 0

I am trying to send a username and password from an iOS app using AFNetworking framework to a php script. The iOS app continues to receive status code 401 which I defined to be “not enough parameters”. I have tried returning the “username” from the php script to the iOS app and receive .

Based on what I’ve been investigating so far, it seems as though:

1) The php script is not decoding the POST parameters properly

2) The iOS app is not sending the POST parameters properly

The following is the iOS function

- (IBAction)startLoginProcess:(id)sender
{

NSString *usernameField = usernameTextField.text;
NSString *passwordField = passwordTextField.text;

NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:usernameField,        @"username", passwordField, @"password", nil];

NSURL *url = [NSURL URLWithString:@"http://localhost/~alejandroe1790/edella_admin/"];

AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
[httpClient defaultValueForHeader:@"Accept"];

[httpClient setParameterEncoding:AFJSONParameterEncoding];

[httpClient postPath:@"login.php" parameters:parameters
             success:^(AFHTTPRequestOperation *operation, id response) {
                 NSLog(@"operation hasAcceptableStatusCode: %d", [operation.response statusCode]);
             }
             failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                 NSLog(@"Error with request");
                 NSLog(@"%@",[error localizedDescription]);
             }];

}

The following is the php script

function checkLogin()
{

    // Check for required parameters
    if (isset($_POST["username"]) && isset($_POST["password"]))
    {
        //Put parameters into local variables
        $username = $_POST["username"];
        $password = $_POST["password"];

        $stmt = $this->db->prepare("SELECT Password FROM Admin WHERE Username=?");
        $stmt->bind_param('s', $username);
        $stmt->execute();
        $stmt->bind_result($resultpassword);
        while ($stmt->fetch()) {
            break;
        }
        $stmt->close();

        // Username or password invalid
        if ($password == $resultpassword) {
            sendResponse(100, 'Login successful');
            return true;
        }
        else 
        {
            sendResponse(400, 'Invalid Username or Password');
            return false;
        }
    }
    sendResponse(401, 'Not enough parameters');
    return false;
}

I feel like I may be missing something. Any assistance would be great.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:30:46+00:00Added an answer on June 13, 2026 at 8:30 pm

    The problem is that you are setting the parameter encoding to JSON and they are being set to the HTTP Body by the AFHTTPClient class. You can get around this and use $_POST by not setting the encoding to JSON.

    - (IBAction)startLoginProcess:(id)sender
    {
    
    NSString *usernameField = usernameTextField.text;
    NSString *passwordField = passwordTextField.text;
    
    NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:usernameField,        @"username", passwordField, @"password", nil];
    
    NSURL *url = [NSURL URLWithString:@"http://localhost/~alejandroe1790/edella_admin/"];
    
    AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
    [httpClient defaultValueForHeader:@"Accept"];
    
    [httpClient postPath:@"login.php" parameters:parameters
                 success:^(AFHTTPRequestOperation *operation, id response) {
                     NSLog(@"operation hasAcceptableStatusCode: %d", [operation.response statusCode]);
                 }
                 failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                     NSLog(@"Error with request");
                     NSLog(@"%@",[error localizedDescription]);
                 }];
    
    }
    

    However, you can send your parameters as a JSON string if you choose, but you won’t be able to use $_POST and will need to json_decode $HTTP_RAW_POST_DATA

    function checkLogin()
    {
        global $HTTP_RAW_POST_DATA;
        // remove the second argument or pass false if you want to use an object
        $user_info = json_decode($HTTP_RAW_POST_DATA, true);
        // Check for required parameters
        if (isset($user_info["username"]) && isset($user_info["password"]))
        {
            //Put parameters into local variables
            $username = $user_info["username"];
            $password = $user_info["password"];
    
            $stmt = $this->db->prepare("SELECT Password FROM Admin WHERE Username=?");
            $stmt->bind_param('s', $username);
            $stmt->execute();
            $stmt->bind_result($resultpassword);
            while ($stmt->fetch()) {
                break;
            }
            $stmt->close();
    
            // Username or password invalid
            if ($password == $resultpassword) {
                sendResponse(100, 'Login successful');
                return true;
            }
            else 
            {
                sendResponse(400, 'Invalid Username or Password');
                return false;
            }
        }
        sendResponse(401, 'Not enough parameters');
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to send data(a username and password) to an online form from
I'm trying to send username and password data from a web form to my
I am trying to send a website my username or password using some jar
I am trying to send an e-mail using php script but i am getting
am trying send an array to php file using $_POST ,still always getting an
I am trying to send emails from smtps (secure smtp) using Indy and the
I am trying to send an email via GMail's SMTP server from a PHP
Am trying to send a mail to recipient from iPhone app without user's interaction.
I am trying to send Email using java mail API from with in a
I'm trying to send mail from my Grails app with mail plugin. It worked

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.