fmpros Posted February 16, 2009 Share Posted February 16, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/145481-please-help-a-newbie-form-submission-url-forwarding/ Share on other sites More sharing options...
MadTechie Posted February 17, 2009 Share Posted February 17, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/145481-please-help-a-newbie-form-submission-url-forwarding/#findComment-763936 Share on other sites More sharing options...
fmpros Posted February 17, 2009 Author Share Posted February 17, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/145481-please-help-a-newbie-form-submission-url-forwarding/#findComment-764366 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.