Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

  • 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";

}

?>

Try changing this:

$loginResult= $login->FMFindAny();

to

$loginResult= $login->FMFind();

Good Luck.

Garry

  • 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.

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

  • 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?

  • 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

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

  • 4 weeks later...

Have you tried adding:

echo $loginResult['errorCode'];

or

print_r($loginResult);

To see if anything obvious is showing up?

  • 4 months later...

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

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.