Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,047 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,547 people online right now. Registration is fast and FREE... Join Now!




logging as both admin and user

 
Reply to this topicStart new topic

logging as both admin and user

msvp4u
24 Jul, 2008 - 09:31 AM
Post #1

New D.I.C Head
*

Joined: 15 Jul, 2008
Posts: 37


My Contributions
i have a table named loginuser
its field names are
1.usrid
2.fname
3.lname
4.usrname
5.pass
6.conf pass


My main_login .php code is as follows

CODE

<html>
<body>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="check_login.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Login Name</td>
<td width="6">:</td>
<td width="294"><input name="loginname" type="text" id="loginname"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="password" type="password" id="password"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</body>
</html>



my check_login.php looks like this

CODE


<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$userpassword=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="loginuser"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$userpassword")or die("Cannot connect to the Data Base");
mysql_select_db("$db_name")or die("Cannot select DB");

// username and password sent from form
$loginname=$_POST['loginname'];
$password=$_POST['password'];
$enpassword=md5($password);

// To protect MySQL injection
$loginname = stripslashes($loginname);
$password = stripslashes($password);
$loginname = mysql_real_escape_string($loginname);
$password = mysql_real_escape_string($password);
//echo "$loginname";
//echo "$password";
//$sql="SELECT * FROM $tbl_name WHERE usrname ='$username' and pass='$pass'";
//$result=mysql_query($sql)or die(mysql_error());

$sql="SELECT usrid FROM loginuser WHERE usrname = '$username' AND pass ='$enpassword';";
$result=mysql_query($sql)or die(mysql_error());


// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

//while ($row = mysql_fetch_array($result)) {
//$count=mysql_num_rows($result);
// $username = $row["username"];
//echo "$username";
//}
//echo "$count";
// If result matched $loginname and $password, table row must be 1 row

if($count==1){

// Register $loginname, $password and redirect to file "login_success.php"
session_register("txtLoginName");
session_register("txtPassWord");
header("location:./menu.php");
}
else {
echo "Wrong Username or Password";
}
?>




in the menu.php i have to display different screens to admin and users how could i do it??



User is offlineProfile CardPM
+Quote Post

MitkOK
RE: Logging As Both Admin And User
24 Jul, 2008 - 12:36 PM
Post #2

D.I.C Regular
Group Icon

Joined: 9 Aug, 2007
Posts: 314



Thanked: 12 times
Dream Kudos: 250
My Contributions
Hi, pal.

I see that you you're usign very weird logic or may be I just don't get it.

You have form with fields for username and password, when they're entered in check_login.php you select usrid for this username and password. Why is that ?

I want to ask you if usrid is unique ?

And how exactly do you make the difference between admin and user ?
User is offlineProfile CardPM
+Quote Post

msvp4u
RE: Logging As Both Admin And User
24 Jul, 2008 - 01:53 PM
Post #3

New D.I.C Head
*

Joined: 15 Jul, 2008
Posts: 37


My Contributions
[quote]

my table description is as follows

CREATE TABLE loginuser(
usrid MEDIUMINT(10) NOT NULL AUTO_INCREMENT,
fname CHAR(50) NOT NULL,
lname CHAR(50) NOT NULL,
usrname VARCHAR(20) NOT NULL,
pass VARCHAR(32) BINARY NOT NULL,
confpass VARCHAR(32) BINARY NOT NULL,
PRIMARY KEY(usrid)
);


i want to use sessions and by using it i should be able to login as admin and user

let me know if i should change my table, if so detail me of how it should be changed

this is where i m erring. help me out to solve this

User is offlineProfile CardPM
+Quote Post

MitkOK
RE: Logging As Both Admin And User
24 Jul, 2008 - 02:29 PM
Post #4

D.I.C Regular
Group Icon

Joined: 9 Aug, 2007
Posts: 314



Thanked: 12 times
Dream Kudos: 250
My Contributions
If I understand you right, you could add filed 'admin' for example and whene registering user/admin this field should be 1 or 0 for example.
Then when you/somene else login yiu'll check if 'admin' field is 1 or 0 and decide what file to redirect.
User is offlineProfile CardPM
+Quote Post

msvp4u
RE: Logging As Both Admin And User
24 Jul, 2008 - 02:38 PM
Post #5

New D.I.C Head
*

Joined: 15 Jul, 2008
Posts: 37


My Contributions
[quote yes i think you r near to my logic. could you please elabroate on it please
[/quote]

User is offlineProfile CardPM
+Quote Post

msvp4u
RE: Logging As Both Admin And User
24 Jul, 2008 - 02:56 PM
Post #6

New D.I.C Head
*

Joined: 15 Jul, 2008
Posts: 37


My Contributions
should i insert a column in my table named <i>admin mediumint(1) not null,</i>
User is offlineProfile CardPM
+Quote Post

MitkOK
RE: Logging As Both Admin And User
24 Jul, 2008 - 03:03 PM
Post #7

D.I.C Regular
Group Icon

Joined: 9 Aug, 2007
Posts: 314



Thanked: 12 times
Dream Kudos: 250
My Contributions
Dude, I strongly recommend you once again to read some tutorials or books and then ask questions.

I 'm repeating myself

1. You add 'admin' field to your database table

2. Registration: Add chebox f.e "Admin", if this box is checked -> you write 1 into field for this user

3. Authentication : When you/someone login check if admin field is 1.

This post has been edited by MitkOK: 24 Jul, 2008 - 03:05 PM
User is offlineProfile CardPM
+Quote Post

msvp4u
RE: Logging As Both Admin And User
24 Jul, 2008 - 03:11 PM
Post #8

New D.I.C Head
*

Joined: 15 Jul, 2008
Posts: 37


My Contributions
thanks dude i dont mind in you asking me to read tutorials i am still a learner. I will do the necessary changes and keep you posted
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 05:16PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month