View Single Post
Old 10-11-2012, 05:27 PM   PM User | #1
nani_nisha06
Regular Coder

 
Join Date: Oct 2012
Location: mother land --india
Posts: 159
Thanks: 37
Thanked 2 Times in 2 Posts
nani_nisha06 is an unknown quantity at this point
Admin page redirect

Hi all,

here I come with new project and however I am using old scrip .

my new project requirement is .

1) If admin login he should go to admin_main.php.

2) If normal user login he should go to main.php.

I know I should create data based field for usergroup and fill it with 1 or 0.

I should need your help making above conditions work on below code.


Code:
<?php session_start(); ?>
<?php
$host="localhost"; // Host name 
$username="test"; // Mysql username 
$password="1234"; // Mysql password 
$db_name="test"; // Database name 
$tbl_name="members"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = hash('sha256', $salt.$mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

if (mysql_num_rows($result) === 1) {

// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION['myusername']=$myusername;

// $_SESSION['LoggedIn'] = 1;
header("location:main.php");
}
else {
//echo "Wrong Username or Password";
header("location:wrong.php");
}
?>
nani_nisha06 is offline   Reply With Quote