halm1985 Posted May 26, 2007 Share Posted May 26, 2007 I use dreamweaver in designing my a web-based project .. There are three types of users : Students, Instuctors and Admins Each user category has a prefex in ID .. e.g. st0001 or in0003 which is submitted with a password upon log-in What i need is to customize log-in based on the first two chracters of the user ID In other words , how to perform the following using PHP ? IF user ID starts with "st" Then go to student.php else If User ID starts with "in" Then go to instructor.php Note : All user IDs and Passwords are stored in a Credentials tabel in the database Quote Link to comment https://forums.phpfreaks.com/topic/53090-solved-customized-log-in-using-php/ Share on other sites More sharing options...
AndyB Posted May 26, 2007 Share Posted May 26, 2007 substr ->http://ca.php.net/manual/en/function.substr.php header ->http://ca.php.net/manual/en/function.header.php (to redirect to a defined URL Quote Link to comment https://forums.phpfreaks.com/topic/53090-solved-customized-log-in-using-php/#findComment-262256 Share on other sites More sharing options...
MadTechie Posted May 26, 2007 Share Posted May 26, 2007 the basic is here <?php $ID = "st0001"; if(substr($ID, 0, 2) == "st") { //goto student } ?> Quote Link to comment https://forums.phpfreaks.com/topic/53090-solved-customized-log-in-using-php/#findComment-262257 Share on other sites More sharing options...
halm1985 Posted May 26, 2007 Author Share Posted May 26, 2007 I got the idea but still don't know where exactly to implement this code, there are 3 cases ( student, instructor, admin) this is the code generated by Dreamweaver for access to only students page, T1 is the name of the UserID text box if (isset($_POST['t1'])) { $loginUsername=$_POST['t1']; $password=$_POST['t2']; $MM_fldUserAuthorization = ""; $MM_redirectLoginSuccess = "student_designed.php"; $MM_redirectLoginFailed = "try_again.html"; $MM_redirecttoReferrer = true; mysql_select_db($database_test, $test); $LoginRS__query=sprintf("SELECT ID, Password FROM credentials WHERE ID='%s' AND Password='%s'", get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); $LoginRS = mysql_query($LoginRS__query, $test) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = ""; //declare two session variables and assign them $_SESSION['MM_Username'] = $loginUsername; $_SESSION['MM_UserGroup'] = $loginStrGroup; if (isset($_SESSION['PrevUrl']) && true) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); } Quote Link to comment https://forums.phpfreaks.com/topic/53090-solved-customized-log-in-using-php/#findComment-262297 Share on other sites More sharing options...
MadTechie Posted May 26, 2007 Share Posted May 26, 2007 it would be something like this if (isset($_POST['t1'])) { $ID = $_POST['t1'] if(substr($ID, 0, 2) == "st") { $MM_redirectLoginSuccess = "student_designed.php"; $loginUsername= "student";//$_POST['t1']; $password=$_POST['t2']; } $MM_fldUserAuthorization = ""; that should give you a push in the right direction Quote Link to comment https://forums.phpfreaks.com/topic/53090-solved-customized-log-in-using-php/#findComment-262310 Share on other sites More sharing options...
halm1985 Posted May 26, 2007 Author Share Posted May 26, 2007 Thanks very much for your help .. i'll work on that Quote Link to comment https://forums.phpfreaks.com/topic/53090-solved-customized-log-in-using-php/#findComment-262312 Share on other sites More sharing options...
halm1985 Posted May 26, 2007 Author Share Posted May 26, 2007 if(substr($ID, 0, 2) == "st") this line causes the following error in the PHP page Parse error: syntax error, unexpected T_IF in C:\wamp\www\login.php on line 14 Quote Link to comment https://forums.phpfreaks.com/topic/53090-solved-customized-log-in-using-php/#findComment-262317 Share on other sites More sharing options...
AndyB Posted May 26, 2007 Share Posted May 26, 2007 Nothing intrinsically wrong with that line. Please post lines 1-15 of your code. Quote Link to comment https://forums.phpfreaks.com/topic/53090-solved-customized-log-in-using-php/#findComment-262321 Share on other sites More sharing options...
MadTechie Posted May 26, 2007 Share Posted May 26, 2007 $ID = $_POST['t1'] should be $ID = $_POST['t1']; Quote Link to comment https://forums.phpfreaks.com/topic/53090-solved-customized-log-in-using-php/#findComment-262322 Share on other sites More sharing options...
halm1985 Posted May 26, 2007 Author Share Posted May 26, 2007 That's what i made $id = $_POST['t1']; if(substr($id, 0, 2) == 'st') { $MM_redirectLoginSuccess = "student_designed.php"; $loginUsername=$_POST['t1']; $password=$_POST['t2']; } else if(substr($id, 0, 2) == 'in') { $MM_redirectLoginSuccess = "instructor_designed.php"; $loginUsername=$_POST['t1']; $password=$_POST['t2']; } else if(substr($id, 0, 2) == 'ad') { $MM_redirectLoginSuccess = "admin_designed.php"; $loginUsername=$_POST['t1']; $password=$_POST['t2']; } The question is where to put the code of redirection in case of log-in failure $MM_fldUserAuthorization = ""; $MM_redirectLoginFailed = "try_again.html"; $MM_redirecttoReferrer = true; mysql_select_db($database_test, $test); this code always executes and goes direcltly to the TRY AGAIN Page Quote Link to comment https://forums.phpfreaks.com/topic/53090-solved-customized-log-in-using-php/#findComment-262326 Share on other sites More sharing options...
MadTechie Posted May 26, 2007 Share Posted May 26, 2007 may help if $test was being set Quote Link to comment https://forums.phpfreaks.com/topic/53090-solved-customized-log-in-using-php/#findComment-262328 Share on other sites More sharing options...
halm1985 Posted May 27, 2007 Author Share Posted May 27, 2007 Finally I did .. Thank you very much MadTechie , Andy The following made it work if (isset($_POST['textfield1'])) { $loginUsername=$_POST['t1']; $password=$_POST['textfield2']; $MM_fldUserAuthorization = ""; if(substr($loginUsername, 0, 2) == 'st') $MM_redirectLoginSuccess = "student.php"; if(substr($loginUsername, 0, 2) == 'in') $MM_redirectLoginSuccess = "instructor.php"; if(substr($loginUsername, 0, 2) == 'ad') $MM_redirectLoginSuccess = "admin.php"; $MM_redirectLoginFailed = "try_again.html"; $MM_redirecttoReferrer = true; mysql_select_db($database_test, $test); ... ... .. Thanks again people Quote Link to comment https://forums.phpfreaks.com/topic/53090-solved-customized-log-in-using-php/#findComment-262531 Share on other sites More sharing options...
MadTechie Posted May 27, 2007 Share Posted May 27, 2007 well done can you please click solved (bottom left) Quote Link to comment https://forums.phpfreaks.com/topic/53090-solved-customized-log-in-using-php/#findComment-262534 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.