programming for PHP and MySQL

5 pts.
Tags:
MySQL
PHP
how do i get my login page to direct a user to an appropriate page depending on user username, password and domain previlidges from a database. am using php and mysql

Answer Wiki

Thanks. We'll let you know when a new response is added.

The simple solution would be to create a field on the database, and name it something like user_lvl
in mysql, it would be something like this:
<pre>ALTER TABLE `table_name` ADD `user_lvl` INT( 3 ) NOT NULL ;</pre>
that gives you a field that will allow you to give people with a level attached to their account. up to 1000 levels. (I usually do int(1), which gives me up to 10 levels). Next, you will need to check their info on the database, and set their privilages accordingly:

<pre>
<?php
/* start up a session for this login, so we can keep track of them */
session_start();

/* put sql data here */

/* END sql data */
/* Run query to see if they are valid */
$sql = “SELECT * FROM `<table name>` WHERE `username`='{addslashes($_POST[‘username’]}’ AND `password` = ‘{addslashes($_POST[‘password’])}’ LIMIT 1;”;

$result=mysql_query($sql);
while ($row = mysql_fetch_assoc($result) && $row[‘user_lvl’] != “0”){
/* ok, they are valid, run this: */
$_SESSION[‘is_valid’] = true;
$_SESSION[‘user_level’] = $row[‘user_level’];
$_SESSION[‘whatever’]=$row[‘you_get_the_idea’];
if($_SESSION[‘user_level’] == “0”){
header(“location:directthemsomewhere1.php”);
exit();
{
if($_SESSION[‘user_level’] == “1”){
header(“location:directthemsomewhere2.php”);
exit();
{

}
/* they are not valid, boot them somewhere you want */
header(“location:index.php?login=bad”);
exit();</pre>

That’s not the most secure way of doing that, but it should give you a starting point from which to build. I made a couple of assumptions about your request. The first assumption was that you meant that you wanted to allow them to have only certain privileges for your domain, not that you wanted to check against an LDAP architecture. The second assumption I made was that you know how to handle sessions, and know where to place them on your site, to utilize them effectively. If my assumptions were incorrect, please let me know.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following