!!HELP!! Login Box issue...

Silvalite

Baseband Member
Messages
73
Location
New Zealand
Hey Guys - haven't been on in ages (haven't really needed much help lately). Anyways, I am making a website, and I want to add an Admin Control Panel. I want this so my staff can access a password protected page and do things other views can't (view site stats, post information, talk to other admins/staff etc.). I already have a login box sorted, but I need a way to get users registered and so when they try and login, if they arn't registered it won't let them. I'm guessing I need a database to do this. I really want to just keep it really simple as I have absolutely no knowledge with mysql or whatever. Can someone please help!

Thanks,
Silvalite110
 
Hi,

The first thing that I would say is that if you don't have your login connected then you don't really have login sorted. To expand a little on that I don't want it to seem like you haven't done the hard part because you have. It is just that without having a place to store your login information setting up and admin panel is not helpful to you at this time. I would start by posting the code that you have so far, and then we can work with you to figure where you need to expand.
 
Hi,

The first thing that you need to do is create a simple form. One that has all the fields that you want, name, username, email, etc. Then you will need to work on a php script to collect all that information and send it somewhere or to someone. Have a look at forms for more help with the first part.

When you finish that I can look it over for you. You can post it up here unless you are comfortable with it.
 
That is fine. Have a look at php form. It will give you a little beginning. If you post the code for your html form then I can have a look at it and write some php code for you.
 
If you have setup the database to store your user login info that is the first step then it is just a matter of placing a form like this

Code:
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="checklogin.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">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>

you will then need code to check the info typed

Code:
<?php
$host="localhost"; // Host name 
$username=""; // Mysql username 
$password=""; // 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 = mysql_real_escape_string($mypassword);

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

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword"); 
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>

this is the core of the process you will then need to protect the page

Code:
<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
    header('WWW-Authenticate: Basic realm="My Realm"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Text to send if user hits Cancel button';
    exit;
} else {
    echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
    echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
}
?>

hope that helps

I write all my code in php pages
 
Back
Top Bottom