September 23, 200520 yr Newbies Hi All, I'm trying to set-up a simple login with the code below on the response page. The code executes fine when the account and password are correct but blows out (does not echo "stuffed" or anything else I put in the 'else' section of the 'if' statement) when the account and password do not match. Any ideas would be much appreciated. <?php session_start(); // basic includes for FXphp include_once("FX/FX.php"); include_once("FX/server_data.php"); include_once("FX/FMErrors.php"); // other set-up $formurl="admin_login.php"; $nexturl="admin_options.php"; // collect variables $accountName=$_POST['account']; $password=$_POST['password']; // perform data checks if (empty($accountName) || empty($password)) { $_SESSION[accountName]=$accountName; $_SESSION[password]=$password; header( "Location: $formurl" ); exit ; } if ($accountName=="webuser") { header( "Location: $formurl" ); exit ; } // create a new instance $login=new FX($serverIP,$webCompanionPort); $login->setDBData('lb_artworks.fp7','webuser'); $login->SetDBPassword($password,$accountName); $loginResult= $login->FMFindAny(); // check authorised login if ($loginResult['foundCount'] == 1) { header( "Location: $nexturl" ); exit ; } else { echo "stuffed"; } ?>
September 23, 200520 yr Try changing this: $loginResult= $login->FMFindAny(); to $loginResult= $login->FMFind(); Good Luck. Garry
September 27, 200520 yr Author Newbies Thanks Gary, But I get the same result. I've added a DBParam of a guaranteed recid and it works fine it the account name and password are correct but blows out if it is not a correct combination.
September 28, 200520 yr In the OS X Console look for any http errors. You may be able to tell if the php is "breaking" whenever the login is incorrect. This maybe caused by FM sending a http reject message! Good Luck. Garry
September 30, 200520 yr Author Newbies Garry et al, After a little tidying up the only thing the Console is showing up under the httpd>errors option is the following... [error] PHP Fatal error: Cannot use object of type FX_Error as array in admin_check.php on line 20 Also, under the Console Webserver Access log I get... "POST /fmi/xml/FMPXMLRESULT.xml? HTTP/1.1" 200 2078 for a successful login and... "POST /fmi/xml/FMPXMLRESULT.xml? HTTP/1.1" 401 615 for a failed login. So the question is how do you deal with a 401 response?
October 1, 200520 yr Author Newbies Hi All, Solution for now is to create an html display of the Failed Login message prior to actually trying to login. That way if a 401 header is sent to the browser preventing any further output the error message (and try again form) has already been displayed. If the login is successful the re-direct to the next page works quickly enough that the user never gets a chance to see the error message. Cheers, Chris
October 2, 200520 yr Chris, Try using the PHP error suppression operator '@': $loginResult= @$login->FMFind(); I've never tried it like that, however worth a go. All the best. Garry
October 25, 200520 yr Have you tried adding: echo $loginResult['errorCode']; or print_r($loginResult); To see if anything obvious is showing up?
March 16, 200619 yr I believe this will catch the error (somewhat) gracefully. This may require PHP 5. Replace this code: // check authorised login if ($loginResult['foundCount'] == 1) { header( "Location: $nexturl" ); exit ; } else { echo "stuffed"; } with this: // check authorised login if (FX::isError($loginResult)) { echo "Error contacting database: " . $loginResult->getMessage(); echo "stuffed"; } if ($loginResult['foundCount'] == 1) { header( "Location: $nexturl" ); exit ; } else { echo "stuffed"; } This catches an error from FMFindAny(), however the error message I get back when the password and username are wrong was not descriptive: "Error contacting database: FX: ExecuteQuery XML error: Mismatched tag at line 6"
Create an account or sign in to comment