Jump to content

php different login and user control


rebornishard

Recommended Posts

i have homework about this but i don't know how to make it work,

after a few hours it stuck with every login will go to same place

 

i must create 4 id :

1.owner : can access all page , edit all id

2.chasier : report any item out, only access item out page (item.php)

3.warehouse : add item from purchasing department, add new item, get notification from chasier, tell purchasing department to buy item

4.purchasing department : get notification from warehouse, sent report to warehouse after add stock or add new item

 

 

login.php

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

 

cek_login.php

<?php
$host="localhost";  
$username="root"; 
$password=""; 
$db_name="shop_system"; 
$tbl_name="members"; 

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");


$username=$_POST['username']; 
$password=$_POST['password'];
$usertype=$_GET['usertype'];

$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);

$sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$password' ";
$result=mysql_query($sql);


$count=mysql_num_rows($result);



if($count==1){

session_register("username");
session_register("password");
header("location:sukses.php");
}
else {
echo "Wrong Username or Password";
}
?>

 

sukses.php

<? 
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
?>

<html>
<body>
Login Successful
</body>
</html>

Link to comment
Share on other sites

My advice, be consisant with your code.  Even small stuff like <? and <?php

 

I cek_login.php, you are not setting your sessions correctly.

In sukses.php, you are not referencing the same session name you are trying to use.

Link to comment
Share on other sites

<? is referred to as short tags.  If a server does not have short tags enabled in their php.ini file, your code will not work.  <?php would be preferred.

 

In regards to sessions, I would recommend doing a quick session tutorial on the web, just do a google search there are a ton out there.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.