Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 5th, 2006, 08:03 AM
Registered User
 
Join Date: Feb 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default admin login

Hi I have created a login page(auth.php) where both users(student) and admin can login where the data is matched from the two tales in mysql database. The only problem is that when both types of users sucessfully login, they are directed to the index page. I would like the admin users to be directed to an admin home page instead (admin_index) and am unsure on how to do this.

If anyone can help mw with this by adjusting the code or otherwise then i would be very grateful. Thanks!

<?
// Login & Session
// auth.php

// select database
include("mysql_connect.php");

// start session
session_start();

// convert username and password from _POST or _SESSION
if($_POST){
  $_SESSION['username']=$_POST["username"];
  $_SESSION['password']=$_POST["password"];
}

// query for matching username and password for all users
$query="SELECT student.username, student.password, staff.username, staff.password
FROM student, staff
WHERE student.username='" . $_SESSION['username'] . "' and student.password='" . $_SESSION['password'] . "'
OR staff.username='" . $_SESSION['username'] . "' and staff.password='" . $_SESSION['password'] . "'";

$results=mysql_query ($query)
    or die(mysql_error());

// retrieve number of rows resulted
$num=mysql_num_rows($results);

// print login form and exit if failed.
//This will only appear in the login page and won't show on subsequent pages when auth is called.
if($num < 1){

  echo "<H1><P><Center>Login</H1></P></Center>";
  echo "<center>You are not authenticated. Please login.<br><br>

  <form method=POST action=index.php>
  username: <input type=text name=\"username\">
  password: <input type=password name=\"password\">
  <input type=submit name=submit value=Login></center>
  </form>";

  exit;
}
?>

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to redirect an non-registered admin to login nrlahoti ASP.NET 2.0 Professional 4 November 26th, 2007 08:47 AM
CMS - admin login does not work peppie BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 2 October 20th, 2007 08:46 AM
I can't login admin account all chapter ? pop99 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 5 June 4th, 2006 05:17 AM
Admin login help banned Classic ASP Databases 2 May 8th, 2006 07:50 PM
can't login into PHPNuke as admin anshul Pro PHP 0 August 5th, 2004 04:16 AM



All times are GMT -4. The time now is 06:43 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.