In this tutorial we will be covering Login.
We will be making three files
connect.php <--to connect to the database
login.php <--that will have the login form on it
auth.php <--will authorize the login, making sure the info is correct.
So first off your going to need to make a "connect.php" so that the login script can connect to the mysql database to get, and submit info.
connect.php
Now im using "WAMP" as so i can set up PHP and MySQL dependent sites on my localhost.PHP Code:<?php
$db = mysql_connect("localhost","root","") or die("Could not connect to db");
if(!$db)
die("no db");
if(!mysql_select_db("database",$db))
die("No Database Selected");
?>
Because you will need to set up a MySQL database for this.
login.phpPHP Code:$db = mysql_connect("localhost","Mysqlusername","Mysqlpassword")
if(!mysql_select_db("Mysqldatabasename",$db))
auth.phpPHP Code:<form method="POST" action="auth">
User Name
<input type="text" name="name" size="21">
<br>
Password
<input type="password" name="password" size"21" mask="x">
<br>
<input type="submit" value="Login" name="submit">
</form>
So you should really get to know how MySQL databases /php works before trying these sort of things, im kind of in a rush right now so i cant explain it much, so if you have any questions just PMPHP Code:<?php
include_once 'connect.php';
session_start();
if (isset($_POST['submit']))
{
$user=$_POST['name'];
$password=$_POST['password'];
$user=strip_tags($user);
$password=strip_tags($password);
$password=md5($password);
$query = "select name, password from user where name='$user' and '$password'";
$result = mysql_query($query) or die("COULD NOT QUERY USER");
$result2 = mysql_fetch_array($result);
if ($result2)
{
$_SESSION['name']=$user;
?>
<script type="text/javascript">
window.location = "index.php"
</script>
<?php
}
else
{
echo "<big>Wrong Username Or Password.<a href='login.php'>Try Again</a></big>";
}
}
?>
Enjoy
__________________________________________________ _______________________________
Originally made for Tech Forumz


LinkBack URL
About LinkBacks





Reply With Quote
Bookmarks