Jump to content

Please help a newbie - Form Submission / URL forwarding


Recommended Posts

I'm trying to build a login process that appears to be beyond my experience.  I'm using PHP with FileMaker Pro as a backend, although I believe the FMP specific calls are irrelevant as the problem therein lies with my PHP code.

 

Here is my login script that is included on my login page.  I need users to be redirected to one page or another depending on the context. 

 

The site I'm building is intended to provide test results.  Users must register their test ID after creating  valid login credentials.  Users will be able to register more than one test.  If the user has previously registered tests, I need the PHP to redirect the user to one of two pages after logging in. 

 

[*]If a user is prompted to login via my "results" page, I'd like the user to be forwarded to the page that displays their test results.

[*]If a user is prompted to login via my "test registration" page, I'd like the user to end up on my test registration form

 

I know that I can do this if I build two separate login forms/scripts although I'd LOVE to know how to do this dynamically. Ideally, I'd like to use the one script and one login form.  Here is the script I have written:

 

 


<?php if(!session_id()) session_start();?>

 

$error = '';

 

$from = $_GET['from'];

 

if(POST('action') == 'login') {

$userFind = $db->newFindCommand('fmp_layout');

$userFind->addFindCriterion('Email','=='.POST('email'));

$userFind->addFindCriterion('Password','=='.POST('password'));

$userResult = $userFind->execute();

 

 

 

 

if(FileMaker::isError($userResult)) {

$error = 'Incorrect username or password';

}else{

if(!session_id()) session_start();

 

session_cache_limiter('private');

$cache_limiter = session_cache_limiter();

 

/* set the cache expire to 30 minutes */

session_cache_expire(30);

$cache_expire = session_cache_expire();

 

      $records = $userResult->getRecords();

              $recid = $records[0]->getRecordId();

$record = $db->getRecordById('fm_layout', $recid);

$id = $record->getField('fm_field');

 

$_SESSION['login_user'] = POST('email');

$_SESSION['login_pass'] = POST('password');

$_SESSION['recid'] = $recid;

$_SESSION['id'] = $id;

$_SESSION['isLoggedin'] = 'true';

 

if(!isset($_SESSION['from'])  {

header('Location: page1.php');

exit();

}else{

header('Location: page2.php');

exit();

}

 

}

}

 

if(GET('action') == 'logout') {

if(!session_id()) session_start();

//erase all session variables

$_SESSION = array();

//destroy the session.

session_destroy();

$error = 'You have been logged out';

}

?>

 


 

For whatever reason, I can't get the "header" calls to work correctly.  What am I doing wrong?  Any insight would be greatly appreciated.  Thanks!

 

 

 

 

Hello and Welcome to PHPFreaks..

 

Nice to see a FMP Developer. personally i don't use FMP for web based development (but i know friends who do)

However his doesn't seam to be FMP Related but purely down to sessions..

So..

 

[*]If a user is prompted to login via my "results" page, I'd like the user to be forwarded to the page that displays their test results.

[*]If a user is prompted to login via my "test registration" page, I'd like the user to end up on my test registration form

At the start of the results page have this code

session_start();
$_SESSION['from'] = "results-url-goes-here";

 

At the start of the registration page have this code

session_start();
$_SESSION['from'] = "registration-url-goes-here";

 

The update

      if(!isset($_SESSION['from'])  {
         header('Location: page1.php');
         exit();
      }else{
         header('Location: page2.php');
         exit();
      }      

 

to

      if(isset($_SESSION['from'])  {
         //header('Location: '.$_SESSION['from']); //Uncomment this line after testing
         echo 'WILL LOAD: '.$_SESSION['from']; //remove this line after testing
         exit();
      }else{
         header('Location: index.php'); //Default page after login
         exit();
      }      

 

Hope that helps

Thanks a bunch for taking the time to post a solution.  I'll give it a try.  Much appreciated!  The FileMaker Pro PHP API is pretty slick.  I'm certain we will see more FMP/PHP developers as time goes on.

 

Thanks again!

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.