+ 4
How can I store user login & logout time on PHP
I want to make a attendance system & want to monitor user login & logout time. How to code for this?
18 Answers
+ 4
can we do like that we will make code and when someone login witt his account I will be informed the username and password of that user at my gmail or at any other site in php.
+ 3
Usually you must to do that with database but if you want you can do it in a log file.
You must to save time next to login and when you logout. Make a file or database where you save user por user id, time and login or logout
+ 3
First question, do you have connect to DB from php server? Or you want to know how make connect to DB and how work with DB from php?
+ 3
and your database struct or MySQL code? please share it
+ 3
All DB has function to get current date and time:
For oracle it is - select sysdate from dual;
For postgres it is - select now();
You can find function for your DB and use it to save date in table.
+ 3
https://code.sololearn.com/w9x9vIMr47au/?ref=app
For begin you can check my code which save time and date in a file but you can use it for database too. Obviously you must to do changes for your code. You must to put store time next to login and next to logout.
Maybe if you share your database struct we can help you more.
+ 2
Could you share database struct or MySQL code?
+ 2
Yes I have connect to DB
+ 2
And of course, if @xec has reason then I think you can use these predefined functions, maybe is faster and easier.
+ 2
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="login.css">
</head>
<body>
<div class="login-page">
<form class="form" action="logout.php" method="post">
<input type="text" name="id" placeholder="employee id"/>
<input type="password" name="password" placeholder="password"/>
<button name="in" type="submit">IN</button>
<button name="out" type="submit">OUT</button>
</form>
</div>
</body>
</html>
<?php
$db= mysqli_connect("localhost", "root", "", "digital attendance");
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$result=0;
$id= mysqli_real_escape_string($db,$_POST['id']);
$password= mysqli_real_escape_string($db,$_POST['password']);
$result = mysqli_query($db,"SELECT name FROM employee_information WHERE id='$id' && password='$password' ");
if(mysqli_num_rows($result) >0 )
{
while($row=mysqli_fetch_assoc($result)){
$name= $row['name'];
}
session_start();
$_SESSION['name']=$name;
date_default_timezone_set("Asia/Dhaka");
$date=date("h:i:sa");
$time=date("d-m-Y", time());
$sql = "INSERT INTO detail(emp_id, emp_name, dated, intime) VALUES('$id', '$name', '$date','$time')";
mysqli_query($db, $sql);
}
else
echo 'The username or password is incorrect';
}
?>
this is my code for send data passing from my page to DB.
But it won't work
+ 1
How to I transfer the data in my database?
I mean what is the code for it?
+ 1
Right, Mr. Daniel.
When one of user login,
I want to transfer the login time in my database, & so that for log out time also
+ 1
Can you help me plz!
+ 1
What is happen? You see error or what? Add echo'' in code and look on result after each step.
0
So do you want to save data time for login and logout to a database?
0
To try to help and check error logs is better to have access to the real server. Please feel free to write to danifdez79@hotmail.com
0
Hi did you get a perfect way to do this? Please use mysqli and php for this. after the login query create a query to update your mysql database with time() and user_id to identify user. and on logout put the query just before session destroy... "-)
0
I got that bro