469,342 Members | 6,453 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,342 developers. It's quick & easy.

how to redirect login page to two different users

amit sabal
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     //Start session
  3.     session_start();
  4.  
  5.     //Include database connection details
  6.     require_once('config.php');
  7.  
  8.     //Array to store validation errors
  9.     $errmsg_arr = array();
  10.  
  11.     //Validation error flag
  12.     $errflag = false;
  13.  
  14.     //Connect to mysql server
  15.     $link = mysql_connect("localhost","root","");
  16.     if(!$link) {
  17.         die('Failed to connect to server: ' . mysql_error());
  18.     }
  19.  
  20.     //Select database
  21.     $db = mysql_select_db("shekhar");
  22.     if(!$db) {
  23.         die("Unable to select database");
  24.     }
  25.  
  26.     //Function to sanitize values received from the form. Prevents SQL injection
  27.     function clean($str) {
  28.         $str = @trim($str);
  29.         if(get_magic_quotes_gpc()) {
  30.             $str = stripslashes($str);
  31.         }
  32.         return mysql_real_escape_string($str);
  33.     }
  34.  
  35.     //Sanitize the POST values
  36.     $login = clean($_POST['login']);
  37.     $password = clean($_POST['password']);
  38.  
  39.     //Input Validations
  40.     if($login == '') {
  41.         $errmsg_arr[] = 'Login ID missing';
  42.         $errflag = true;
  43.     }
  44.     if($password == '') {
  45.         $errmsg_arr[] = 'Password missing';
  46.         $errflag = true;
  47.     }
  48.  
  49.     //If there are input validations, redirect back to the login form
  50.     if($errflag) 
  51.     {
  52.         $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
  53.         session_write_close();
  54.         header("location: index.php");
  55.         exit();
  56.     }
  57.  
  58.     //Create query
  59.     $qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'";
  60.     $result=mysql_query($qry);
  61.  
  62.         //Check whether the query was successful or not
  63.         if($result)
  64.         {
  65.             if(mysql_num_rows($result) == 1)
  66.             {
  67.                 //Login Successful
  68.                 session_regenerate_id();
  69.                 $member = mysql_fetch_assoc($result);
  70.                 $_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
  71.                 $_SESSION['SESS_FIRST_NAME'] = $member['firstname'];
  72.                 $_SESSION['SESS_LAST_NAME'] = $member['lastname'];
  73.                 session_write_close();
  74.                 header("location: member-index.php");
  75.                 exit();
  76.             }
  77.             else
  78.             {
  79.                 //Login failed
  80.                 header("location: login-failed.php");
  81.                 exit();
  82.             }
  83.        }
  84.  
  85.  
  86.     else
  87.     {
  88.         die("Query failed");
  89.     }
  90. ?>
Apr 22 '11 #1
8 5758
dlite922
1,584 Expert 1GB
What's your question? which part of the code is causing the issue? Does it currently work? Throw errors?

DM
Apr 22 '11 #2
my ques is, i want the login page to be redirected to two different page as per user, if admin login it will show the different page and if user login it will show the different page.i m checking the login detail with the stored database.ya this code is working fine.
Apr 23 '11 #3
dlite922
1,584 Expert 1GB
OK, so your line where it says redirect, you just put some logic there.

Expand|Select|Wrap|Line Numbers
  1. if ($admin) {
  2.  redirect to admin page
  3. } else
  4.  redirect to user page
  5. }
How you check for admin is up to you. I suggest another field in your database to say that user123 is admin or not. If you have one admin user always and forever, then create a user with user_id = 1 and login name to be "admin". Check the user_id and login to see if this is admin.

Advise: Don't store the admin flag in the SESSION, always check the database every time you want to know a user is admin. This way someone can't hijack your session and set this variable themselves. (This can easily be done).

Dan
Apr 24 '11 #4
Sweet and discreet, this one speed mini bullet vibe features a built-in finger ring for pinpointing pleasure, a waterproof body for aquatic enjoyment, and a shiny metallic finish for eyecatching style. Easily clipped to a key chain or worn as a pendant, the sleek look of this mini bullet vibrator will ensure only you know the true purpose! The Kinki Stix Finger Ring Massager even comes with a battery to start the fun right away!
Apr 25 '11 #5
Sweet and discreet, this one speed mini bullet vibe features a built-in finger ring for pinpointing pleasure, a waterproof body for aquatic enjoyment, and a shiny metallic finish for eyecatching style. Easily clipped to a key chain or worn as a pendant, the sleek look of this mini bullet vibrator will ensure only you know the true purpose! The Kinki Stix Finger Ring Massager even comes with a battery to start the fun right away!
Apr 25 '11 #6
Sweet and discreet, this one speed mini bullet vibe features a built-in finger ring for pinpointing pleasure, a waterproof body for aquatic enjoyment, and a shiny metallic finish for eyecatching style. Easily clipped to a key chain or worn as a pendant, the sleek look of this mini bullet vibrator will ensure only you know the true purpose! The Kinki Stix Finger Ring Massager even comes with a battery to start the fun right away!
Apr 26 '11 #7
Sweet and discreet, this one speed mini bullet vibe features a built-in finger ring for pinpointing pleasure, a waterproof body for aquatic enjoyment, and a shiny metallic finish for eyecatching style. Easily clipped to a key chain or worn as a pendant, the sleek look of this mini bullet vibrator will ensure only you know the true purpose! The Kinki Stix Finger Ring Massager even comes with a battery to start the fun right away!
Apr 26 '11 #8
pix of naked sex scene Naked art .
Apr 26 '11 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Kenneth Keeley | last post: by
3 posts views Thread by Tom Nowak | last post: by
reply views Thread by Michael Groeger | last post: by
1 post views Thread by Anders Jacobsen | last post: by
3 posts views Thread by =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.