Hey guys, I'm brand new to iOS development, and I'm trying to create
an app that will be based off of a website that a friend of mine has
already created. There is a login.php file that handles login and
keeping track of the session. I'm trying to use an ASIFormDataRequest
to submit a POST to the login script that just needs the username and
password. But after a day of Googling, I can't figure out what is
wrong. The 'action' is nothing special, just another parameter
right? Tried a bunch of stuff and failed. Here's a snippet of
the .php and my Objective-C code.
.php
------
<?php
session_start();
$intPageUsageID = 0;
include_once("Application.php");
include_once("$GlobalIncPath/dbconn.php");
// If this page is being called as a login, process the login
if ($_POST['action']=="login") {
include_once("$GlobalIncPath/class.user.php");
// Construct new User object
$UserObject = new User($db, $ErrorMsg);
$UserLogin = $UserObject->UserLogin($_POST['username'],
$_POST['password']);
if (empty($ErrorMsg)){// Login was successful so load he lunch
details for today
include_once("$GlobalIncPath/class.lunch.php");
// Construct new Lunch object
$LunchObject = new Lunch($db, $ErrorMsg);
$LunchDetail = $LunchObject->LunchDetail($UserLogin['UserID']);
}
// Set session variables after logging in
$_SESSION['intUserID'] = $UserLogin['UserID'];
$_SESSION['intAdmin'] = $UserLogin['Admin'];
$_SESSION['strDefZip'] = $UserLogin['DefaultZip'];
$_SESSION['numDefLat'] = $UserLogin['Lat'];
$_SESSION['numDefLon'] = $UserLogin['Lon'];
if (isset($_SESSION['intUserID'])){
$_SESSION['strUsername'] = $_POST['username'];
}
if (!empty($_POST['fpg'])||!empty($_GET['fpg'])) {
$fpg = urldecode($_POST['fpg']).urldecode($_GET['fpg']);
header("location:".$fpg); // Redirect
exit;
}
header("location:index.php"); // Redirect
}
// If this page is being called as a logout, redirect to logout.php
if ($_POST['action']=="logout") {
header("location:Logout.php"); // Redirect
}
code
------
NSURL *url = [NSURL URLWithString:@"
http://myurl.com"];
ASIFormDataRequest *request = [ASIFormDataRequest
requestWithURL:url];
[request setPostValue:@"login" forKey:@"action"];
[request setPostValue:usernameField.text forKey:@"username"];
[request setPostValue:passwordField.text forKey:@"password"];
// [request setPassword:passwordField.text];
// [request setUsername:usernameField.text];
NSLog(@"Request data: %@", request);
[request startSynchronous];
NSError *error = [request error];
if (!error) {
NSString *response = [request responseString];
NSLog(@"response = %@", response);
}
else {
NSLog(@"ERROR = %@", [error localizedFailureReason]);
}