+ 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?

9th Aug 2017, 12:14 AM
ASHRAFUL HAQUE SULAIMAN
ASHRAFUL HAQUE SULAIMAN - avatar
18 ответов
+ 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.
8th Nov 2017, 10:13 AM
Arpan Kanwer
+ 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
9th Aug 2017, 2:03 AM
Daniel
Daniel - avatar
+ 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?
9th Aug 2017, 9:20 PM
xec
+ 3
and your database struct or MySQL code? please share it
10th Aug 2017, 4:47 AM
Daniel
Daniel - avatar
+ 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.
10th Aug 2017, 6:37 AM
xec
+ 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.
10th Aug 2017, 2:10 PM
Daniel
Daniel - avatar
+ 2
Could you share database struct or MySQL code?
9th Aug 2017, 6:51 PM
Daniel
Daniel - avatar
+ 2
Yes I have connect to DB
10th Aug 2017, 4:18 AM
ASHRAFUL HAQUE SULAIMAN
ASHRAFUL HAQUE SULAIMAN - avatar
+ 2
And of course, if @xec has reason then I think you can use these predefined functions, maybe is faster and easier.
10th Aug 2017, 2:11 PM
Daniel
Daniel - avatar
+ 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
10th Aug 2017, 6:01 PM
ASHRAFUL HAQUE SULAIMAN
ASHRAFUL HAQUE SULAIMAN - avatar
+ 1
How to I transfer the data in my database? I mean what is the code for it?
9th Aug 2017, 3:35 PM
ASHRAFUL HAQUE SULAIMAN
ASHRAFUL HAQUE SULAIMAN - avatar
+ 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
9th Aug 2017, 6:46 PM
ASHRAFUL HAQUE SULAIMAN
ASHRAFUL HAQUE SULAIMAN - avatar
+ 1
Can you help me plz!
9th Aug 2017, 6:47 PM
ASHRAFUL HAQUE SULAIMAN
ASHRAFUL HAQUE SULAIMAN - avatar
+ 1
What is happen? You see error or what? Add echo'' in code and look on result after each step.
10th Aug 2017, 6:39 PM
xec
0
So do you want to save data time for login and logout to a database?
9th Aug 2017, 4:35 PM
Daniel
Daniel - avatar
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
10th Aug 2017, 6:19 PM
Daniel
Daniel - avatar
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... "-)
21st Feb 2018, 7:48 PM
Okeyo Tom Lepski
Okeyo Tom Lepski - avatar
0
I got that bro
26th Feb 2018, 8:09 AM
Arpan Kanwer