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

  • Home
  • SEARCH
  • 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 6325905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:58:55+00:00 2026-05-24T16:58:55+00:00

So i got the following problem: I got a login viewcontroller and a form

  • 0

So i got the following problem:

I got a login viewcontroller and a form viewcontroller. On the login viewcontroller, i am sending a POST request to a PHP script which validates if the user has access. The script just returns an 1 or 0. So i can then choose to dismiss or maintain the viewcontroller. When the credentials are passed right, the user will see the form controller. This controller got a button to fetch a form.

The button to fetch the form, makes a POST request to another PHP script, which will return an XML document with the values of the user. I need a way to remember the username and password the user has passed through. So i can use them in another (view) controller.

Does anybody know a way to achieve this?

  • 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-24T16:58:56+00:00Added an answer on May 24, 2026 at 4:58 pm

    If you’re using NSURLConnection, and the session is cookie based, this would automatically be done. So all you’d need to write would be similar to this

    NSMutableURLRequest *request = nil;
    request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://server.com/login.php"]];
    
    NSString *post = [NSString stringWithFormat:@"username=%@&password=%@", @"<username>", @"<password>"];
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    [request setValue:[NSString stringWithFormat:@"%d", [postData length]] forHTTPHeaderField:@"Content-Length"];
    [request setTimeoutInterval: 15];
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:postData];
    
    _urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    [_urlConnection start];
    

    And you would have to implement the NSURLConnectionDelegate methods as well

    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
        [_responseData appendData:data];
    }
    
    - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
        //Oops! handle failure here
    }
    
    - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
        if (_statusCode >= 200 && _statusCode < 400) {
                //Things look ok
            NSString *responseString = [[[NSString alloc] initWithData:_responseData] autorelease];
            //Send this to an xml lib and parse
            }
    
        [_responseData release];
        _responseData = nil;
        [connection autorelease];
    }
    

    If you have some other information thats in the headers and which you need to send back with consequent requests, you can read it from the response like this

    - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
        if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
            NSDictionary *headerFields = [(NSHTTPURLResponse*)response allHeaderFields]; //This would give you all the header fields;
        }
    }
    

    And set the header fields for the next request like this

        [request setValue:[NSString stringWithFormat:@"%d", [postData length]] forHTTPHeaderField:@"Content-Length"];
    

    To save information, be it username and/or password or session information you can use NSUserDefaults

        //To save
    NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
    
    if (standardUserDefaults) {
        [standardUserDefaults setObject:@"<username>" forKey:@"username"];
        [standardUserDefaults setObject:@"<pass>" forKey:@"password"];
        [standardUserDefaults synchronize];
    }
    
    //To retrieve
    NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
    NSString *val = nil;
    
    if (standardUserDefaults) 
        val = [standardUserDefaults objectForKey:@"username"];
    

    Lastly, it would be advisable to build a model to map the xml API with [Eg: a User class with username and password properties].

    Google for Apple’s docs on MVC.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got the following problem since the server has safe mode turned on,
So I've got a save button on my form, which has a callback function
I've got the following query to determine how many votes a story has received:
i´ve got a problem to get jpa running. Following exception appears when i try
I have Ajax login form, which is checking whether given credentials are correct and
I got the following class : class ConstraintFailureSet(dict, Exception) : Container for constraint failures.
I've got the following SQL: select * from transaction_log where stoptime like '%2008%' How
I've got the following in my .css file creating a little image next to
I've got the following situation A rails application that makes use of rjs /
I've got the following JavaScript on my web page... 64 var description = new

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.