Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] Ostatnie logowanie (data i ip)
Napster
post 19.08.2008, 00:09:35
Post #1





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 31.05.2008

Ostrzeżenie: (0%)
-----


Witam. Mam problem ze zrobieniem ostatniego logowania (data i ip). Gdy poprawnie zalogujemy się poprzez formularz:

  1. <?php
  2. $data = date("Y-m-d");
  3. $czas = date("G:i");
  4. $ip = $_SERVER['REMOTE_ADDR'];
  5.  
  6.  
  7. $lastlogin = mysql_query
  8. ("UPDATE uzytkownicy SET `lastlogin`='$data ' '$czas' WHERE `login`='$usname' LIMIT 1");
  9.  
  10. $lastip = mysql_query
  11. ("UPDATE uzytkownicy SET `lastip`='$ip' WHERE `login`='$usname' LIMIT 1");
  12. ?>


to aktualizauje się kolumna lastlogin i lastip do aktualnych danych, po czym są wyświetlane w panelu użytkownika.
To bezsensu bo zawsze będzie pojawiać się aktualna data a nie np. data logowania i ip z wczoraj czy chociażby kilka godzin wcześniej.

Jak to rozwiązać?

Ten post edytował Napster 19.08.2008, 00:10:08
Go to the top of the page
+Quote Post
rybik
post 19.08.2008, 00:27:25
Post #2





Grupa: Zarejestrowani
Postów: 99
Pomógł: 15
Dołączył: 29.07.2006

Ostrzeżenie: (0%)
-----


rozwiązać tam gdzie problem, problemem jest to, że zapisujesz inną datę niż wyświeltasz, zatem masz dwie daty, czyli musisz zapisać obie, czyli pamiętać dwa ostatnie logowania

1. Przepisz nowe na stare, zapamiętaj
2. Nadpisz nowe
Go to the top of the page
+Quote Post
Crozin
post 19.08.2008, 09:58:01
Post #3





Grupa: Zarejestrowani
Postów: 6 476
Pomógł: 1306
Dołączył: 6.08.2006
Skąd: Kraków

Ostrzeżenie: (0%)
-----


Przed uaktualnieniem tych danych musisz je sobie pobrać
  1. <?
  2.  
  3. //gdy uzytkownik poprawnie przeszedl etap logowania
  4. $r = mysql_query('SELECT lastlogin, lastip FROM uzytkownicy WHERE userID = xxxx');
  5. $_SESSION['lastlogin'] = $r['lastlogin'];
  6. $_SESSION['lastip'] = $r['lastlip'];
  7.  
  8. mysql_query('UPDATE uzytkownicy SET lastip = "' . $_SERVER['REMOTE_ADDR'] . '", lastlogin = ' . date('Y-m-d G:i') . ' WHERE userID = xxx');
  9. ?>
Go to the top of the page
+Quote Post
Napster
post 19.08.2008, 13:32:30
Post #4





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 31.05.2008

Ostrzeżenie: (0%)
-----


Za bardzo nie rozumiem, kiedy ma być zmieniana data?
Go to the top of the page
+Quote Post
Crozin
post 19.08.2008, 13:38:51
Post #5





Grupa: Zarejestrowani
Postów: 6 476
Pomógł: 1306
Dołączył: 6.08.2006
Skąd: Kraków

Ostrzeżenie: (0%)
-----


Najpierw pobierasz sobie do zmiennych sesyjnych dane o ostatnim logowaniu (data i ip) a dopiero potem to nadpisujesz.
Go to the top of the page
+Quote Post
woxala123
post 31.01.2016, 10:06:35
Post #6





Grupa: Zarejestrowani
Postów: 361
Pomógł: 12
Dołączył: 9.01.2010

Ostrzeżenie: (10%)
X----


No dobrze! Ja mam podobny temat ale jak je wyswietlić?
Go to the top of the page
+Quote Post
com
post 31.01.2016, 16:00:29
Post #7





Grupa: Zarejestrowani
Postów: 3 034
Pomógł: 366
Dołączył: 24.05.2012

Ostrzeżenie: (0%)
-----


sprecyzuj i daj kod smile.gif
Go to the top of the page
+Quote Post
woxala123
post 31.01.2016, 16:06:50
Post #8





Grupa: Zarejestrowani
Postów: 361
Pomógł: 12
Dołączył: 9.01.2010

Ostrzeżenie: (10%)
X----


Witam Ciebie com. Temat podobny jest tutaj i kod też Temat: PHPWylogowanie i zapisanie do bazy danych ostatniego logowania. Zależy mnie by w profil.php gdzie jest zalogowany user wyświetlał mi datę ostatniego logowania. Dodam jeszcze plik profile.php
  1. <?php require_once('Connections/local.php'); ?>
  2. <?php
  3. if (!isset($_SESSION)) {
  4. }
  5. $MM_authorizedUsers = "";
  6. $MM_donotCheckaccess = "true";
  7.  
  8. if (isset($_SESSION['username']))
  9. ?>
  10.  
  11.  
  12.  
  13. <?php echo $_SESSION['username'];
  14.  
  15. // *** Restrict Access To Page: Grant or deny access to this page
  16. function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
  17. // For security, start by assuming the visitor is NOT authorized.
  18. $isValid = False;
  19.  
  20. // When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
  21. // Therefore, we know that a user is NOT logged in if that Session variable is blank.
  22. if (!empty($UserName)) {
  23. // Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
  24. // Parse the strings into arrays.
  25. $arrUsers = Explode(",", $strUsers);
  26. $arrGroups = Explode(",", $strGroups);
  27. if (in_array($UserName, $arrUsers)) {
  28. $isValid = true;
  29. }
  30. // Or, you may restrict access to only certain users based on their username.
  31. if (in_array($UserGroup, $arrGroups)) {
  32. $isValid = true;
  33. }
  34. if (($strUsers == "") && true) {
  35. $isValid = true;
  36. }
  37. }
  38. return $isValid;
  39. }
  40.  
  41. $MM_restrictGoTo = "register.php";
  42. if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
  43. $MM_qsChar = "?";
  44. $MM_referrer = $_SERVER['PHP_SELF'];
  45. if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  46. if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0)
  47. $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  48. $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  49. header("Location: ". $MM_restrictGoTo);
  50. }
  51. ?>
  52.  
  53. <?php echo $_SESSION['lastlogin']; ?>
  54.  
  55. <?php
  56. if (!function_exists("GetSQLValueString")) {
  57. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  58. {
  59. if (PHP_VERSION < 6) {
  60. $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  61. }
  62.  
  63. $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  64.  
  65. switch ($theType) {
  66. case "text":
  67. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  68. break;
  69. case "long":
  70. case "int":
  71. $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  72. break;
  73. case "double":
  74. $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  75. break;
  76. case "date":
  77. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  78. break;
  79. case "defined":
  80. $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  81. break;
  82. }
  83. return $theValue;
  84. }
  85. }
  86.  
  87. $colname_Recordset1 = "-1";
  88. if (isset($_SESSION['MM_Username'])) {
  89. $colname_Recordset1 = $_SESSION['MM_Username'];
  90. }
  91. mysql_select_db($database_local, $local);
  92. $query_Recordset1 = sprintf("SELECT * FROM userlogin WHERE username = %s", GetSQLValueString($colname_Recordset1, "text"));
  93. $Recordset1 = mysql_query($query_Recordset1, $local) or die(mysql_error());
  94. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  95. $totalRows_Recordset1 = mysql_num_rows($Recordset1);
  96.  
  97. $colname_Recordset2 = "-1";
  98. if (isset($_SESSION['lastlogin'])) {
  99. $colname_Recordset2 = $_SESSION['lastlogin'];
  100. }
  101. mysql_select_db($database_local, $local);
  102. $query_Recordset2 = sprintf("SELECT lastlogin FROM userlogin WHERE lastlogin = %s", GetSQLValueString($colname_Recordset2, "date"));
  103. $Recordset2 = mysql_query($query_Recordset2, $local) or die(mysql_error());
  104. $row_Recordset2 = mysql_fetch_assoc($Recordset2);
  105. $totalRows_Recordset2 = mysql_num_rows($Recordset2);
  106.  
Go to the top of the page
+Quote Post
com
post 31.01.2016, 16:10:16
Post #9





Grupa: Zarejestrowani
Postów: 3 034
Pomógł: 366
Dołączył: 24.05.2012

Ostrzeżenie: (0%)
-----


no to poco 2 tematy?
Go to the top of the page
+Quote Post
woxala123
post 31.01.2016, 16:11:50
Post #10





Grupa: Zarejestrowani
Postów: 361
Pomógł: 12
Dołączył: 9.01.2010

Ostrzeżenie: (10%)
X----


Szukałem i tutaj rozwiązania i chciałem ten temat trochę ruszyć. Ale możemy wrócić do tego 1 tematu.
Go to the top of the page
+Quote Post
com
post 31.01.2016, 16:14:39
Post #11





Grupa: Zarejestrowani
Postów: 3 034
Pomógł: 366
Dołączył: 24.05.2012

Ostrzeżenie: (0%)
-----


tu jest odpowiedź na twoje pytania dla mysql, tam gdzie masz w pdo wstaw to w mysql i gotowe biggrin.gif
Go to the top of the page
+Quote Post
woxala123
post 31.01.2016, 16:26:36
Post #12





Grupa: Zarejestrowani
Postów: 361
Pomógł: 12
Dołączył: 9.01.2010

Ostrzeżenie: (10%)
X----


Nie wiem jak wstawić pdo w mysql. Tym zajmę się sie póżniej. Na razie szukam rozwiązania w mysql. Pozdrawiam
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 12.06.2025 - 12:00