Jump to content


Photo

Access logs php/mysql


  • Please log in to reply
13 replies to this topic

#1 miz_luvly@hotmail.com

miz_luvly@hotmail.com
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 06 June 2006 - 12:48 PM

Hi Guyz

After getting assistance on the previous posts, here I am with another one. I want to record the time when user login and logout of the web. I have searched through the web and found web stats and access counters etc but I dont need something as detailed as that I have a very small website with users given login passwords to go and add reports (done in php/mysql). Can someone direct me to a suitable tutorial or a sample I can look at -- thanks.



#2 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 06 June 2006 - 04:00 PM

[!--quoteo(post=380577:date=Jun 6 2006, 08:48 AM:name=sab)--][div class=\'quotetop\']QUOTE(sab @ Jun 6 2006, 08:48 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hi Guyz

After getting assistance on the previous posts, here I am with another one. I want to record the time when user login and logout of the web. I have searched through the web and found web stats and access counters etc but I dont need something as detailed as that I have a very small website with users given login passwords to go and add reports (done in php/mysql). Can someone direct me to a suitable tutorial or a sample I can look at -- thanks.
[/quote]

just add something like this after the login verification is succesful

$logged = date("H:i:s");

and UPDATE it in your user's table

same thing for loggout, just make sure you make 2 new rows in your database, one for the time they logged in and the other for the time they logged out

#3 miz_luvly@hotmail.com

miz_luvly@hotmail.com
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 07 June 2006 - 09:02 AM

[!--quoteo(post=380640:date=Jun 6 2006, 11:00 AM:name=digitalgod)--][div class=\'quotetop\']QUOTE(digitalgod @ Jun 6 2006, 11:00 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
just add something like this after the login verification is succesful

$logged = date("H:i:s");

and UPDATE it in your user's table

same thing for loggout, just make sure you make 2 new rows in your database, one for the time they logged in and the other for the time they logged out
[/quote]

thanks for the reply but if I use update I will overwrite the login/logout time. I want keep the old login as well as new one.

I might need a new table for this but not sure. Also how can i have 2 timestamp columns in a table one for login and one for logout

you help is much appreciated

thanks

#4 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 07 June 2006 - 10:57 AM

[!--quoteo(post=380926:date=Jun 7 2006, 05:02 AM:name=sab)--][div class=\'quotetop\']QUOTE(sab @ Jun 7 2006, 05:02 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
thanks for the reply but if I use update I will overwrite the login/logout time. I want keep the old login as well as new one.

I might need a new table for this but not sure. Also how can i have 2 timestamp columns in a table one for login and one for logout

you help is much appreciated

thanks
[/quote]


you can have as many timestamp columns in a table as you want. If you want to keep the old login you'll probably have to make a new table with just: id users login_time logout_time , where users is the name of your user that logged in/out.

#5 miz_luvly@hotmail.com

miz_luvly@hotmail.com
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 07 June 2006 - 11:12 AM

[!--quoteo(post=380940:date=Jun 7 2006, 05:57 AM:name=digitalgod)--][div class=\'quotetop\']QUOTE(digitalgod @ Jun 7 2006, 05:57 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
you can have as many timestamp columns in a table as you want. If you want to keep the old login you'll probably have to make a new table with just: id users login_time logout_time , where users is the name of your user that logged in/out.
[/quote]

But I get error if I put two timestamps. Can you explain how to go about and do this.
thanks

#6 miz_luvly@hotmail.com

miz_luvly@hotmail.com
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 07 June 2006 - 02:19 PM

[!--quoteo(post=380946:date=Jun 7 2006, 06:12 AM:name=sab)--][div class=\'quotetop\']QUOTE(sab @ Jun 7 2006, 06:12 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
But I get error if I put two timestamps. Can you explain how to go about and do this.
thanks
[/quote]

I have solved half of the problem, I have managed to insert login time but how do i insert logout time can any1 help plzzz.
thanks in advance

here is my logout code:

session_start();

$_SESSION['logged_in'] = 0;

setcookie('login_cookie', false, time() - 3600, '/secure/', 'index.php');

mysql_query("update access_log set logout_datetime = date('Y-m-d h:i:sa', time()) ");

session_destroy();

header("Location: index.php");
?>

#7 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 07 June 2006 - 06:15 PM

[!--quoteo(post=380999:date=Jun 7 2006, 10:19 AM:name=sab)--][div class=\'quotetop\']QUOTE(sab @ Jun 7 2006, 10:19 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I have solved half of the problem, I have managed to insert login time but how do i insert logout time can any1 help plzzz.
thanks in advance

here is my logout code:

session_start();

$_SESSION['logged_in'] = 0;

setcookie('login_cookie', false, time() - 3600, '/secure/', 'index.php');

mysql_query("update access_log set logout_datetime = date('Y-m-d h:i:sa', time()) ");

session_destroy();

header("Location: index.php");
?>
[/quote]

mysql_query("UPDATE access_log SET logout_datetime = date('Y-m-d h:i:sa', time()) WHERE id = 1 ");

should do the trick

#8 miz_luvly@hotmail.com

miz_luvly@hotmail.com
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 08 June 2006 - 09:49 AM

[!--quoteo(post=381091:date=Jun 7 2006, 01:15 PM:name=digitalgod)--][div class=\'quotetop\']QUOTE(digitalgod @ Jun 7 2006, 01:15 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
mysql_query("UPDATE access_log SET logout_datetime = date('Y-m-d h:i:sa', time()) WHERE id = 1 ");

should do the trick
[/quote]

The query still not updating logout_datetime column :(
+--------+----------+---------------------+---------------------+
| log_id | username | login_datetime | logout_datetime |
+--------+----------+---------------------+---------------------+
| 1 | abc | 2006-06-07 17:10:35 | 0000-00-00 00:00:00 |
| 2 | abc | 2006-06-07 17:11:49 | 0000-00-00 00:00:00 |
+--------+----------+---------------------+---------------------+
2 rows in set (0.05 sec)

any suggestions?


#9 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 08 June 2006 - 05:49 PM

[!--quoteo(post=381305:date=Jun 8 2006, 05:49 AM:name=sab)--][div class=\'quotetop\']QUOTE(sab @ Jun 8 2006, 05:49 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
The query still not updating logout_datetime column :(
+--------+----------+---------------------+---------------------+
| log_id | username | login_datetime | logout_datetime |
+--------+----------+---------------------+---------------------+
| 1 | abc | 2006-06-07 17:10:35 | 0000-00-00 00:00:00 |
| 2 | abc | 2006-06-07 17:11:49 | 0000-00-00 00:00:00 |
+--------+----------+---------------------+---------------------+
2 rows in set (0.05 sec)

any suggestions?
[/quote]


just replace the part that says WHERE id = 1 with WHERE username = and that variable or session you used to store the username

something like

mysql_query("UPDATE access_log SET logout_datetime = date('Y-m-d h:i:sa', time()) WHERE username = '$username' ");

#10 miz_luvly@hotmail.com

miz_luvly@hotmail.com
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 09 June 2006 - 09:00 AM

[!--quoteo(post=381503:date=Jun 8 2006, 12:49 PM:name=digitalgod)--][div class=\'quotetop\']QUOTE(digitalgod @ Jun 8 2006, 12:49 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
just replace the part that says WHERE id = 1 with WHERE username = and that variable or session you used to store the username

something like

mysql_query("UPDATE access_log SET logout_datetime = date('Y-m-d h:i:sa', time()) WHERE username = '$username' ");
[/quote]

Thanks digitalgod it worked. :)

#11 miz_luvly@hotmail.com

miz_luvly@hotmail.com
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 16 June 2006 - 01:37 PM

[!--quoteo(post=381779:date=Jun 9 2006, 04:00 AM:name=sab)--][div class=\'quotetop\']QUOTE(sab @ Jun 9 2006, 04:00 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Thanks digitalgod it worked. :)
[/quote]

Hi

Here I am again, I thought i have managed to make it work but i didnt. the problem is when I update logout time for specific user, the whole column get updated for example:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]+--------+----------+---------------------+---------------------+
| log_id | username | login_datetime | logout_datetime |
+--------+----------+---------------------+---------------------+
| 1 | abc | 2006-06-07 17:10:35 | 2006-06-16 14:11:29 |
| 2 | def | 2006-06-07 17:11:49 | 2006-06-16 14:11:29 |
| 4 | ghi | 2006-06-16 12:05:02 | 2006-06-16 14:11:29 |
| 5 | jkl | 2006-06-16 12:08:27 | 2006-06-16 14:11:29 |[/quote]

the code is:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?
require "conn.php";

Session_start();

$_SESSION['logged_in'] = 0;
$_SESSION['username'] = $_POST['username'];
$_SESSION['log_id'] = log_id;

setcookie('login_cookie', false, time() - 3600, '/secure/', '.index1.php');

mysql_query("UPDATE access_log SET logout_datetime = now() WHERE log_id=log_id and username=username"); or die (mysql_error());

session_destroy();

header("Location: index1.php");

?>[/quote]

here is my login script:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?
ob_start();
session_start();
$_SESSION['time_start']=$start;
$_SESSION['log_id']= log_id;

if(isset($_SESSION['username']) && isset($_SESSION['password'])) {
header ("Location: page.php");
$sql = mysql_query("INSERT INTO users (first_name, last_name, email_address,
username, password, info, signup_date)
VALUES('$first_name', '$last_name', '$email_address',
'$username', '$db_password', '$info2', now())") or die (mysql_error());
} //end if logged in

if(isset($_POST['submit'])) {

if(!$_POST['username']) die("Error: You must enter your username before logging in.");
if(!$_POST['password']) die("Error: You must enter your password before logging in.");


mysql_query("INSERT INTO access_log (username,login_datetime)
VALUES('$username', now())") or die (mysql_error());

$get_user = mysql_query("SELECT * FROM `users` WHERE username = '".$_POST['username']."' AND

user_password = '".md5($_POST['password'])."'");
$q = mysql_fetch_object($get_user);
if(!$q) die("Login Failure: An error occured, please verify your username and password are correct.");

//set session variables
$_SESSION['logged_in'] = 1;
$_SESSION['log_id']= $_POST['log_id'];
$_SESSION['username'] = $_POST['username'];

session_write_close();

header("Location: page.php");

} else {

//show login form
?>
<html>
<head><title>Rep sign-up page</title>
</head>
<body>
<h4>Existing user please login</h4>
<form name="login" method="post" action="<? $_SERVER['PHP_SELF']; ?>">
<table>
<tr>
<td>Username:<input type="text" id="username" name="username"></td>
</tr>
<tr>
<td>Password:<input type="password" id="password" name="password"></td>
</tr>
<tr>
<td>Submit: <input type="submit" value="Login" name="submit" id="submit"></td>
</tr>
</table>
</form>


</body>
</html>
<?
}//end else

?>[/quote]
Can some1 help plzzz.

thanks in advance

#12 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 16 June 2006 - 02:20 PM


logout.php
<?

require "conn.php";

Session_start();

$_SESSION['logged_in'] = 0;
$_SESSION['username'] = $_POST['username']; 
$_SESSION['log_id'] = log_id;

setcookie('login_cookie', false, time() - 3600, '/secure/', '.index1.php');




if($_GET["cmd"]=="update") {

$logout_datetime=date('Y-m-d h:i:sa', time());
$logout_datetime=$_POST['logout_datetime'];



mysql_query("UPDATE access_log SET logout_datetime = '$logout_datetime' WHERE log_id=log_id and username=username"); or die (mysql_error()); 
}

session_destroy();

header("Location: index1.php");

?>


The link to update and log out.

<a href="logout.php?&cmd=update&log_id=$log_id">Logout</a>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#13 miz_luvly@hotmail.com

miz_luvly@hotmail.com
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 19 June 2006 - 04:18 PM

[!--quoteo(post=384564:date=Jun 16 2006, 09:20 AM:name=redarrow)--][div class=\'quotetop\']QUOTE(redarrow @ Jun 16 2006, 09:20 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]

logout.php
<?

require "conn.php";

Session_start();

$_SESSION['logged_in'] = 0;
$_SESSION['username'] = $_POST['username']; 
$_SESSION['log_id'] = log_id;

setcookie('login_cookie', false, time() - 3600, '/secure/', '.index1.php');
if($_GET["cmd"]=="update") {

$logout_datetime=date('Y-m-d h:i:sa', time());
$logout_datetime=$_POST['logout_datetime'];
mysql_query("UPDATE access_log SET logout_datetime = '$logout_datetime' WHERE log_id=log_id and username=username"); or die (mysql_error()); 
}

session_destroy();

header("Location: index1.php");

?>
The link to update and log out.

<a href="logout.php?&cmd=update&log_id=$log_id">Logout</a>

[/quote]

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]I have tried that but now I get the following:
+--------+----------+---------------------+---------------------+
| log_id | username | login_datetime | logout_datetime |
+--------+----------+---------------------+---------------------+
|     50 |          | 2006-06-19 17:06:49 | 0000-00-00 00:00:00 |
|     51 |          | 2006-06-19 17:07:25 | 0000-00-00 00:00:00 |
|     52 |          | 2006-06-19 17:08:16 | 0000-00-00 00:00:00 |
|     53 |          | 2006-06-19 17:09:33 | 0000-00-00 00:00:00 |
|     54 |          | 2006-06-19 17:10:08 | 0000-00-00 00:00:00 |
+--------+----------+---------------------+---------------------+
Username is blank and logout column remain '0000-00-00 00:00:00'

here is the table structure if helps:
+-----------------+-------------+------+-----+---------------------+------------
----+
| Field           | Type        | Null | Key | Default             | Extra
    |
+-----------------+-------------+------+-----+---------------------+------------
----+
| log_id          | int(25)     | NO   | PRI | NULL                | auto_increm
ent |
| username        | varchar(25) | NO   |     |                     |
    |
| login_datetime  | datetime    | NO   |     | 0000-00-00 00:00:00 |
    |
| logout_datetime | datetime    | NO   |     | 0000-00-00 00:00:00 |
    |
+-----------------+-------------+------+-----+---------------------+------------
Any suggestions plzzz

thanks[/quote]

#14 miz_luvly@hotmail.com

miz_luvly@hotmail.com
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 23 June 2006 - 11:41 AM

please refer to: Posted Jun 16 2006, 08:37 AM
Can anyone help plzzz

Thanks in advance
Sab




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users