472,334 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,334 software developers and data experts.

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 5868
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

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

Similar topics

1
by: Stu | last post by:
Hi All, I have an ASP.NET application to which I have implemented forms authentication to handle security. It is a relatively straight forward...
5
by: Kenneth Keeley | last post by:
Hi, I have a web app that has forms authentication and I can login to the page the first time I go there but it never times me out if I come back...
3
by: Tom Nowak | last post by:
I have written a web app that includes a login page. When a user successfully logs in, they are taken to the main web app page. I have a button...
10
by: GreggTB | last post by:
I've got an page (LOGIN.ASPX) that receives the user's login information. During the page load, it checks the credentials against a database and,...
0
by: Michael Groeger | last post by:
Hi, I have implemented a simple page for FormsAuthentication and when user data is accepted I redirect the user using...
1
by: Anders Jacobsen | last post by:
Hey Im devloping an application in asp.net 1.1 SP2. I need to control timeout values for each user. Im having trouble to make it work. When the...
4
by: jobs | last post by:
Hello. If my users are logged in, and try to access restricted pages I want to direct them to a custom 403 page. If they are not logged in, I...
3
by: pveena | last post by:
Hi, I am new to php. I have two pages.one is login page other is details page. When user enter detaisl page directly in URL i want to redirect...
8
pentahari
by: pentahari | last post by:
Redirect to login page if session("UserName") is expired when the page useraccount.aspx load event My useraccount.aspx code : If...
3
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
I have a asp.net app. When session is invalid, how to redirect user to the login page? I don't want to add the code to redirect user to the login...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.