473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 5923
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 solution with all aspx pages residing in the root...
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 in 24 hours a hit the refresh key the page loads...
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 on this page that I want to use to redirect the...
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, if validation is successful, creates an instance of...
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 FormsAuthentication.RedirectFromLoginPage(). private void...
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 session timouts out I want to redirect the user to...
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 would like to continue to direct them to the login...
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 to login page then login success it should go to...
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 Session("UserName") Is Nothing Then ...
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 page into every page. Thanks, -Billy
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.