Hi, this is a way to Start for you , (if you are using LAMP),
I use the database to store info about users, if you want to manage them later it could by usefull.
1- form.html
CODE
<html>
<head>
<title>Connexion au site</title>
</head>
<body>
<form method="post" action="verifLogin.php">
<table border="0" width="400" align="center">
<tr>
<td width="200"><b>Your login</b></td>
<td width="200">
<input type="text" name="login">
</td>
</tr>
<tr>
<td width="200"><b>Your password<b></td>
<td width="200">
<input type="password" name="pass">
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="submit" value="login">
</td>
</tr>
</table>
</form>
</body>
</html>
2- verif_login.php
CODE
<?php
// start sessions
session_start();
//crypt password with md5
$passe = md5($pass);
$loginOK = false; // cf Astuce
echo 'Welcome '.$login.'<br>';
if ( isset($_POST) && (!empty($_POST['login'])) && (!empty($_POST['pass'])) ) {
extract($_POST); //
require ('config.php');
$sql = "SELECT * FROM logme WHERE user = '".addslashes($login)."'";
$req = mysql_query($sql) or die('Error SQL : <br />'.$sql);
// check user in database
if (mysql_num_rows($req) > 0) {
$data = mysql_fetch_assoc($req);
// check password
if ($passe == $data['pass']) {
$loginOK = true;
echo 'good password<br>';
} else { echo '<br>bad password<br>';
//echo $data['pass'];
echo '<br><a href=/otro/logout.php>go back</a><br>';}
}
}
// if login and password are ok, save them into a session
if ($loginOK) {
$_SESSION['pseudo'] = $data['user'];
$_SESSION['mail'] = $data['mail'];
$_SESSION['etat'] = $data['etat'];
echo '<br>oki session register!!<br>';
if ($_SESSION['etat'] == "ok") { echo 'user ok';
echo '<br><a href=/otro/logout.php>log out</a><br>';
}
else { echo 'sorry, you are not actived'; }
}
else {
echo 'Error, come back later !<br><br>
<a href=/otro/logout.php>home</a><br>';
}
?>
3 - config.php
CODE
<?
$dbhost = "127.0.0.1";
$user = "";
$password = "";
$usebdd = "test";
if (! @$connexion = mysql_connect($dbhost, $user, $password))
{
print("Unable to connect to ".$dbhost);
print("<br>");
exit;
}
// Selection de la BDD
$db = mysql_select_db ($usebdd, $connexion) or die ("probleme de connexion à la base");
?>
and then create the database:
CODE
--
-- Table structure for table `logme`
--
CREATE TABLE `logme` (
`id_user` bigint(100) NOT NULL auto_increment,
`user` varchar(20) NOT NULL default '',
`pass` varchar(100) NOT NULL default '',
`mail` varchar(50) NOT NULL default '',
`etat` varchar(5) NOT NULL default '',
PRIMARY KEY (`id_user`)
) TYPE=MyISAM AUTO_INCREMENT=3;
--
-- Dumping data for table `logme`
--
Sorry for my bad english and i Hope this will help you
ps: use
php freak tutorial to complete the script