Jump to content

[SOLVED] Customized Log-in using PHP


halm1985

Recommended Posts

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

Link to comment
Share on other sites

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 );

  }

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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.