Hey there.
I've got something for you if you want to "secure" your users accounts. It's a log that recieves the login information that people is entering.
People will might think like this: Why sending peoples login information? -> Well, if someone is trying to hack anothers account, and they maybe succeed it, you'll ofc. get it to know from the hacked, and then you can go check the log to see, who is the person that logged into that account.
I will post the code and explain after..
authenticate.php
Code: Select all
<?php
include_once 'connect.php';
session_start();
if (isset($_POST['submit']))
{
$player=$_POST['player'];
$password=$_POST['password'];
$player=strip_tags($player);
$password=strip_tags($password);
$password=md5($password);
$ldate=date("d.m.y H:i");
$query = "select name,password from players where name='$player' and password='$password'";
$result = mysql_query($query) or die("Could not query players");
$result2 = mysql_fetch_array($result);
if ($result2)
{
$_SESSION['player']=$player;
echo "<big>Logged in successfully<br>";
echo "<A href='index.php'>Continue</a></big>";
mysql_query("INSERT INTO loginlog (username, ip, status, password, date) VALUES ('$_SESSION[player]','$_SERVER[REMOTE_ADDR]','success','Not viewable.','$ldate')");
}
else
{
echo "<big>Wrong username or password.<A href='login.php'>Try Again</a></big>";
mysql_query("INSERT INTO loginlog (username, ip, status, password, date) VALUES ('$_POST[player]','$_SERVER[REMOTE_ADDR]','failed','$_POST[password]','$ldate')");
}
}
?>
mySQL:
Code: Select all
CREATE TABLE `loginlog` (
`id` int(15) NOT NULL auto_increment,
`username` varchar(100) NOT NULL,
`ip` varchar(15) NOT NULL,
`status` varchar(20) NOT NULL,
`password` varchar(100) NOT NULL,
`date` varchar(50) NOT NULL,
UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Explanation:
mysql_query("INSERT INTO loginlog (username, ip, status, password, date) VALUES ('$_SESSION[player]','$_SERVER[REMOTE_ADDR]','success','Not viewable.','$ldate')");
- If the users login is an success, the code will enter this in your loginlog. It will insert the players name, which IP the player is logging in from, tell if the login was an success or a fail, "Not viewable." will only be entered if the login is an success, since we wont show their password. And then the login attempt date.
mysql_query("INSERT INTO loginlog (username, ip, status, password, date) VALUES ('$_POST[player]','$_SERVER[REMOTE_ADDR]','failed','$_POST[password]','$ldate')");
- Does the same as the other one, except that it will enter "failed" in status, and it will show the entered password.