473,379 Members | 1,278 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,379 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 5921
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
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.