Jump to content

Ip Logs.


dean7

Recommended Posts

Hi im am trying to code ip logs, so basicly i want it so when users login to my website the ip gets logged. So everytime they login the have there ip logged and saved.

But how would i do it so they can save the log's when they login each time?

 

This is my index.php with the login on.

 

<title>Login</title><?
oB_start();
// allows you to use cookies.
include("config.php");
if (!$logged[username])
{
if (!$_POST[login])
{
echo("
<center><form method=\"POST\">
<table>
<tr>
<td align=\"right\">
Username: <input type=\"text\" size=\"15\" maxlength=\"25\" name=\"username\">
</td>
</tr>
<tr>
<td align=\"right\">
Password: <input type=\"password\" size=\"15\" maxlength=\"25\" name=\"password\">
</td></tr><tr>
<td align=\"center\">
<input type=\"submit\" name=\"login\" value=\"Login\">
</td></tr><tr>
<td align=\"center\">
<a href=\"Register.php\">Register Here</a><br>
Site Closed At The Moment!<br>
</td></tr></table></form></center>");
}
if ($_POST[login]) {
// the form has been submitted.  We continue...
$username=$_POST['username'];
$password = md5($_POST[password]);
// the above lines set variables with the submitted information.  
$info = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());
$data = mysql_fetch_array($info);
if($data[password] != $password) {
// the password was not the user's password!
echo "Incorrect username or password!";
}else{
// the password was right!
$query = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());
$user = mysql_fetch_array($query);
// gets the user's information
setcookie("id", $user[id],time()+(60*60*24*5), "/", "");
setcookie("pass", $user[password],time()+(60*60*24*5), "/", "");
// the above lines set 2 cookies. 1 with the user's id and another with his/her password.  
echo ("<meta http-equiv=\"Refresh\" content=\"0; URL=http://**********/index2.php\"/>Thank You! You will be redirected");
// modify the above line...add in your site url instead of yoursite.com
}
}
}
else
{
}
?>

 

If thats the wrong file please tell me.

 

Thanks for your help :)

Link to comment
https://forums.phpfreaks.com/topic/158641-ip-logs/
Share on other sites

I suggest creating an IP Logs table (maybe called 'ip_logs'). Create it with three fields: user_id, ip_address, timestamp (stores a UNIX timestamp).

 

Then, upon each successful login, insert a new row into the table including the user's ID, IP address, and time stamp, respectively.

 

To grab a user's IP...

 

$ip_address = $_SERVER['REMOTE_ADDR'];

Link to comment
https://forums.phpfreaks.com/topic/158641-ip-logs/#findComment-836675
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.