-1

I would like to store the login, logout and duration time in database.

The name of my database is 'registration' and my tablename is 'users'.

This is the source code im using:

https://codewithawa.com/posts/complete-user-registration-system-using-php-and-mysql-database

Anyone knows how can I do this?

galep
  • 80
  • 7
  • Please share what you've tried so far. As you linked a tutorial post, you're probably trying to learn PHP and MySQL, so just providing you with a code snippet won't help in the long run. – Capricorn Jul 31 '18 at 15:25
  • 3
    Please don't use that code, it teaches many bad habits. (Like not using unique constraints, inappropriate protection against SQL injection, use of weak passwords, and not checking for database errors.) – Alex Howansky Jul 31 '18 at 15:30
  • Possible duplicate of [Login, logout and duration time in php and mysql?](https://stackoverflow.com/questions/1837934/login-logout-and-duration-time-in-php-and-mysql) – Sox - Jul 31 '18 at 15:45
  • Since that so-called login system uses MD5, which is completely useless for security, and doesn't use prepared statements with placeholder values, **DO NOT USE THIS TUTORIAL CODE FOR ANYTHING, NOT EVEN LEARNING**. – tadman Jul 31 '18 at 15:55
  • **WARNING**: Writing your own access control layer is not easy and there are many opportunities to get it severely wrong. Please, do not write your own authentication system when any modern [development framework](http://codegeekz.com/best-php-frameworks-for-developers/) like [Laravel](http://laravel.com/) comes with a robust [authentication system](https://laravel.com/docs/master/authentication) built-in. At the absolute least follow [recommended security best practices](http://www.phptherightway.com/#security) and **never store passwords as plain-text** or a weak hash like **SHA1 or MD5**. – tadman Jul 31 '18 at 15:55
  • Another thing to note is only a very small percentage of your users will actually "log out". Most will log in and only when their session and/or cookies expire will they be logged out. The only way to determine their session length is to examine logs and guess. – tadman Jul 31 '18 at 15:56

1 Answers1

0

I have been testing how it is done but I get many errors with this code ... Am I on track?

session_start(); 
 $_SESSION['username']=$name; 
 date_default_timezone_set('europe/spain')
 $date=date("h:i:sa"); 
 $time=date("d-m-Y", time()); 
 $sql = "INSERT INTO users(id, username, email, password, logintime) VALUES( , , , 
 ,'$time')";
galep
  • 80
  • 7