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 666921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:52:19+00:00 2026-05-13T23:52:19+00:00

Im trying to create a iPhone Objective C login page using PHP/MySQL to authenticate.

  • 0

Im trying to create a iPhone Objective C login page using PHP/MySQL to authenticate. Im trying to use HTTP responses as a way of authenticating. Right now it always fails to login , regardless of what you enter.

`- (IBAction) login: (id) sender
{
// this part isnt really implemented yet!
NSString *post =[NSString stringWithFormat:@"username=%@&password=%@",usernameField.text, passwordField.text];




NSURL *url = [NSURL URLWithString:@"MY URL HERE.php"];


 NSURLRequest *request = [NSURLRequest requestWithURL: url];

 NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)request;
 responseStatusCode = [httpResponse statusCode];


 NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:response error:nil];




 if ([responseStatusCode statusCode] == 200) {
   //do something
   UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"success" message:@"Your have logged in" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
   [alertsuccess show];
   [alertsuccess release];
  }

  else   {
   NSLog(@"Login failed.");
   //do something else
   UIAlertView *alertfail = [[UIAlertView alloc] initWithTitle:@"fail" message:@"login fail" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
   [alertfail show];
   [alertfail release];
  }
`

and the PHP looks like

    <?
session_start();
require("iphoneconnection.php");

$u = $_POST['username'];
$pw = $_POST['password'];

$check = "SELECT username, password FROM iphoneusers WHERE username='$u' AND password= '$pw'";



$login = mysql_query($check, $connect) or die(mysql_error());


// check user level and store in $row

if (mysql_num_rows($login) == 1) {
$row = mysql_fetch_assoc($login);
//$_SESSION['level'] = $row['level'];
$_SESSION['username'] = $u;
echo 'login success';
header("HTTP/1.1 200 OK");

//header("Location: index.php");

} else {
//header("Location: login.php");
//echo '403 Forbidden';
header("403 Forbidden");
}

mysql_close($connect);


?>

Anyone got any pointers? Even if its just to tell me if Im formatting my repsonses correctly in the PHP.

Thanks in advance.

  • 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-05-13T23:52:19+00:00Added an answer on May 13, 2026 at 11:52 pm

    Thanks for the response. I got it to work using:

    - (IBAction) login: (id) sender
    {
    
    NSString *post =[NSString stringWithFormat:@"username=%@&password=%@",usernameField.text, passwordField.text];
    
    NSString *hostStr = @"MY URL.php?";
    hostStr = [hostStr stringByAppendingString:post];
    NSData *dataURL =  [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];    
    NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
    if([serverOutput isEqualToString:@"Yes"]){
        UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"success" message:@"You are authorized"
                                                              delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
        [alertsuccess show];
        [alertsuccess release];
    
    } else {
        UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Fail" message:@"Invalid Access"
                                                              delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
        [alertsuccess show];
        [alertsuccess release];
    
    }
    
    loginIndicator.hidden = FALSE;
    [loginIndicator startAnimating];
    loginButton.enabled = FALSE;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 367k
  • Answers 367k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here is a way: Object yourObject = ...; Class clazz… May 14, 2026 at 5:01 pm
  • Editorial Team
    Editorial Team added an answer Try to run the example made for Cocoa Touch, it's… May 14, 2026 at 5:01 pm
  • Editorial Team
    Editorial Team added an answer I had the same problem as you Ranch. I'm running… May 14, 2026 at 5:01 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.