Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Czas obecności
MajareQ
post 20.03.2008, 12:21:24
Post #1





Grupa: Zarejestrowani
Postów: 382
Pomógł: 22
Dołączył: 21.05.2007
Skąd: Elbląg

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


Wszystko w sesjach mi działa prócz niszczenie sesji i wylogowywania po nieaktywności na stronie przez dany czas .

mam takie coś:

  1. <?php
  2. $czasGasniecia = 900;
  3. $_SESSION['czasObecnosci'] = time();
  4. if ($_SESSION['auth'] == TRUE) {
  5. if ($_SESSION['czasObecnosci'] > $czasGasniecia) {
  6. $zalogujDB = mysql_query("UPDATE kt_admin SET zalogowany=0 WHERE login='".$_SESSION['login']."'");
  7. $_SESSION['auth'] = FALSE;
  8. }
  9. }
  10. ?>


No i niestety nie wszystko mi styka. Wyświetla się biała strona (obsługa błędów od górnie wyłączona przez admina serwa).

update: jeden błąd naprawiłem... jednak teraz wogule nie tworzy mi sesji, nie mogę się zalogować...

Ten post edytował MajareQ 20.03.2008, 12:20:42
Go to the top of the page
+Quote Post
ujex
post 20.03.2008, 20:49:13
Post #2





Grupa: Zarejestrowani
Postów: 51
Pomógł: 1
Dołączył: 4.11.2006

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


Po pierwsze to bez wyświetlania błędów daleko nie "zajedziesz" smile.gif
Spróbuj:

  1. <?php
  2. ini_set('display_errors', true);
  3. ?>

lub
  1. <?php
  2. ?>

Jeżeli to nie pomoże radzę poszukać innego serwera lub samemu coś postawić.

Co do Twojego tematu to domyślam się że chcesz żeby użytkownik został wylogowany po 15 min.
I teraz zobacz: zapisujesz do sesji obecny czas
  1. <?php
  2. $_SESSION['czasObecnosci'] = time();
  3. ?>

a chwile później sprawdzasz czy ten czas jest większy od 900........ warunek jest zawsze spełniony.
Powinno być tak:
  1. <?php
  2. $czasGasniecia = 900;
  3. if ($_SESSION['auth'] == TRUE) {
  4. if (((int) time() - $_SESSION['czasObecnosci']) > $czasGasniecia) {
  5. $zalogujDB = mysql_query("UPDATE kt_admin SET zalogowany=0 WHERE login='".$_SESSION['login']."'");
  6. $_SESSION['auth'] = FALSE;
  7. } else {
  8. $_SESSION['czasObecnosci'] = (int) time();
  9. }
  10. }
  11. ?>
Go to the top of the page
+Quote Post
MajareQ
post 20.03.2008, 21:48:44
Post #3





Grupa: Zarejestrowani
Postów: 382
Pomógł: 22
Dołączył: 21.05.2007
Skąd: Elbląg

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


może za wcześnie dałem pomoga, bo ustawilem dla testu 5 sekund i nie zgasła mi sesja...
Go to the top of the page
+Quote Post
ujex
post 20.03.2008, 21:55:05
Post #4





Grupa: Zarejestrowani
Postów: 51
Pomógł: 1
Dołączył: 4.11.2006

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


Myślę że jak pokażesz więcej kodu to bedzie łatwiej.....
Go to the top of the page
+Quote Post
MajareQ
post 20.03.2008, 21:56:59
Post #5





Grupa: Zarejestrowani
Postów: 382
Pomógł: 22
Dołączył: 21.05.2007
Skąd: Elbląg

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


  1. <?php
  2. ini_set('display_errors', true);
  3. include('db.php');
  4. include('data.php');
  5. include('funkcje.php');
  6. $_SESSION['czasObecnosci'] = time();
  7. $czasGasniecia = 5;
  8. if ($_SESSION['auth'] == TRUE) {
  9. if (((int) time() - $_SESSION['czasObecnosci']) > $czasGasniecia) {
  10. $zalogujDB = mysql_query("UPDATE kt_admin SET zalogowany=0 WHERE login='".$_SESSION['login']."'");
  11. $_SESSION['auth'] = FALSE;
  12. } else {
  13. $_SESSION['czasObecnosci'] = (int) time();
  14. }
  15. }
  16. SesFixiHij ();
  17. ?>


Ten post edytował MajareQ 20.03.2008, 21:57:17
Go to the top of the page
+Quote Post
ujex
post 20.03.2008, 22:01:32
Post #6





Grupa: Zarejestrowani
Postów: 51
Pomógł: 1
Dołączył: 4.11.2006

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


Ja napisałem troche innaczej:)

  1. <?php
  2. ini_set('display_errors', true);
  3. include('db.php');
  4. include('data.php');
  5. include('funkcje.php');
  6. // tego tutaj nie moze byc
  7. //$_SESSION['czasObecnosci'] = time();
  8. $czasGasniecia = 5;
  9. if ($_SESSION['auth'] == TRUE) {
  10. if (((int) time() - $_SESSION['czasObecnosci']) > $czasGasniecia) {
  11. $zalogujDB = mysql_query("UPDATE kt_admin SET zalogowany=0 WHERE login='".$_SESSION['login']."'");
  12. $_SESSION['auth'] = FALSE;
  13. } else {
  14. $_SESSION['czasObecnosci'] = (int) time();
  15. }
  16. }
  17. SesFixiHij ();
  18. ?>


Ten post edytował ujex 20.03.2008, 22:02:33
Go to the top of the page
+Quote Post
MajareQ
post 20.03.2008, 22:06:52
Post #7





Grupa: Zarejestrowani
Postów: 382
Pomógł: 22
Dołączył: 21.05.2007
Skąd: Elbląg

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


Teraz w ogóle nie tworzy mi sesji...

Ten post edytował MajareQ 21.03.2008, 09:21:11
Go to the top of the page
+Quote Post
ujex
post 20.03.2008, 22:17:12
Post #8





Grupa: Zarejestrowani
Postów: 51
Pomógł: 1
Dołączył: 4.11.2006

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


No ja nie wiem gdzie masz tworzoną sesje ja pomagam Ci zrobić skrypt który wyloguje użytkownika po pewnym czasie nieaktywności.
Podejrzewam że musisz mieć gdzieś skrypt który loguje użytkownika po podaniu loginu i hasła i w tym skrypcie zapewne ustawiasz
$_SESSION['auth']=true;
Go to the top of the page
+Quote Post
MajareQ
post 21.03.2008, 09:22:51
Post #9





Grupa: Zarejestrowani
Postów: 382
Pomógł: 22
Dołączył: 21.05.2007
Skąd: Elbląg

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


formularz odsyla sie do pliku który ustawie sesje auth na true i ustawia w bazie admina jako zalogowanego...
Go to the top of the page
+Quote Post
vokiel
post 21.03.2008, 10:48:29
Post #10





Grupa: Zarejestrowani
Postów: 2 592
Pomógł: 445
Dołączył: 12.03.2007

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


  1. <?php
  2. ini_set('display_errors', true);
  3. include('db.php');
  4. include('data.php');
  5. include('funkcje.php');
  6. $_SESSION['czasObecnosci'] = time();
  7. $czasGasniecia = 5;
  8. // chyba chodzi o sprawdzenie czy aktualny czas (w sek) - czas zalogowania (w sek) jest > dopuszczalny czas
  9. //czyli teraz-czasObecnosci>czasGasniecia
  10. if ($_SESSION['auth'] == TRUE) {
  11. if (( intval(time()) - intval($_SESSION['czasObecnosci']) ) > $czasGasniecia) {
  12. $zalogujDB = mysql_query("UPDATE kt_admin SET zalogowany=0 WHERE login='".$_SESSION['login']."'");
  13. $_SESSION['auth'] = FALSE;
  14. } else {
  15. $_SESSION['czasObecnosci'] = (int) time();
  16. }
  17. }
  18. SesFixiHij ();
  19. ?>


--------------------
Go to the top of the page
+Quote Post
MajareQ
post 21.03.2008, 11:52:02
Post #11





Grupa: Zarejestrowani
Postów: 382
Pomógł: 22
Dołączył: 21.05.2007
Skąd: Elbląg

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


nie działczy...

tzn najpierw byl blab i biala strona, naprawile literowke i strona sie wyswietla, ale po 5 sekundach nie gasnie sesja...
Go to the top of the page
+Quote Post
vokiel
post 21.03.2008, 12:00:18
Post #12





Grupa: Zarejestrowani
Postów: 2 592
Pomógł: 445
Dołączył: 12.03.2007

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


Po co kombinujemy zmiane czasu na int smile.gif Można porównać czas normalnie z time() a różnica będzie w sekundach.
Tyle, że:
  1. <?php
  2. // to powinno byc ustawiane w skrypcie przy logowaniu
  3. $_SESSION['czasObecnosci'] = time();
  4. // bo teraz to jest ustawione i od razu sprawdzane, wiec troche nie bangla;)
  5.  
  6. ini_set('display_errors', true);
  7. include('db.php');
  8. include('data.php');
  9. include('funkcje.php');
  10. $czasGasniecia = 5;
  11. if ($_SESSION['auth'] == TRUE) {
  12. if (time() - $_SESSION['czasObecnosci'] ) > $czasGasniecia) {
  13. $zalogujDB = mysql_query("UPDATE kt_admin SET zalogowany=0 WHERE login='".$_SESSION['login']."'");
  14. $_SESSION['auth'] = FALSE;
  15. } else {
  16. $_SESSION['czasObecnosci'] = time();
  17. }
  18. }
  19. SesFixiHij ();
  20. ?>


--------------------
Go to the top of the page
+Quote Post
MajareQ
post 21.03.2008, 12:57:35
Post #13





Grupa: Zarejestrowani
Postów: 382
Pomógł: 22
Dołączył: 21.05.2007
Skąd: Elbląg

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


nie działczy?

biała strona
Go to the top of the page
+Quote Post
vokiel
post 25.03.2008, 10:25:07
Post #14





Grupa: Zarejestrowani
Postów: 2 592
Pomógł: 445
Dołączył: 12.03.2007

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


  1. <?php
  2. // a moze ustawić czas wygaśnięcia sesji:
  3. if( session_cache_expire( ) + 500 < time() ) { 
  4. session_cache_expire( time() + 500 ) 
  5. }
  6. ?>


--------------------
Go to the top of the page
+Quote Post
MajareQ
post 25.03.2008, 13:39:51
Post #15





Grupa: Zarejestrowani
Postów: 382
Pomógł: 22
Dołączył: 21.05.2007
Skąd: Elbląg

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


zapomniałeś ; tongue.gif

  1. <?php
  2. if(session_cache_expire() + 500 < time()) { 
  3. }
  4. ?>


zaraz zobaczę czy działa

no więc mam tak:

Cytat
if(session_cache_expire() + 2 < time()) {
session_cache_expire(time() + 2);
} else {
$zalogujDB = mysql_query("UPDATE kt_admin SET zalogowany=0 WHERE login='".$_SESSION['login']."'");
$_SESSION['auth'] = FALSE;
session_destroy();
}


i nie działczy

nawet jak dam tylko twój kod to wyskakuje:

Cytat
Strict Standards: date(): It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CET/1.0/no DST' instead in /apache/apache-common/virt/virtuals/virt-645341/kt/engine/data.php on line 14 Strict Standards: strftime(): It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CET/1.0/no DST' instead in /apache/apache-common/virt/virtuals/virt-645341/kt/engine/data.php on line 57 25 marca 2008 Strict Standards: date(): It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CET/1.0/no DST' instead in /apache/apache-common/virt/virtuals/virt-645341/kt/engine/head.php on line 113 13:38


i

Cytat
Strict Standards: mktime(): It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CET/1.0/no DST' instead in /apache/apache-common/virt/virtuals/virt-645341/kt/engine/online.php on line 20 Strict Standards: mktime(): You should be using the time() function instead in /apache/apache-common/virt/virtuals/virt-645341/kt/engine/online.php on line 20 Strict Standards: mktime(): It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CET/1.0/no DST' instead in /apache/apache-common/virt/virtuals/virt-645341/kt/engine/online.php on line 22 Strict Standards: mktime(): You should be using the time() function instead in /apache/apache-common/virt/virtuals/virt-645341/kt/engine/online.php on line 22 Strict Standards: date(): It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CET/1.0/no DST' instead in /apache/apache-common/virt/virtuals/virt-645341/kt/engine/online.php on line 23 online: 1
Go to the top of the page
+Quote Post
Trobin
post 25.03.2008, 14:00:47
Post #16





Grupa: Zarejestrowani
Postów: 82
Pomógł: 6
Dołączył: 23.03.2008
Skąd: Szczecin

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


  1. <?php
  2. date_default_timezone_set('Europe/Warsaw');
  3. ?>

Może pomóc na
Cytat
Strict Standards: date():


--------------------
Pracuję na: Apache 2.2.4, MySQL 5.0.20a, PHP 5.3.0
Go to the top of the page
+Quote Post
vokiel
post 25.03.2008, 14:27:56
Post #17





Grupa: Zarejestrowani
Postów: 2 592
Pomógł: 445
Dołączył: 12.03.2007

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


Tak sie zastanawialem, zrobilem test u siebie, i teoretycznie powinno dzialac, moze w tych plikach data.php, albo funkcje.php jest cos co psuje....
  1. <?php
  2. // przy logowaniu
  3. $_SESSION['czasObecnosci'] = time();
  4. ?>

  1. <?php
  2. error_reporting (E_ALL);
  3. include('db.php');
  4. include('data.php');
  5. include('funkcje.php');
  6. $czasGasniecia = 5; // 5 sekund
  7. if ($_SESSION['auth'] == TRUE) {
  8. // zrobmy test (poczekamy 6 sec)
  9. sleep(6);
  10. if ((time() - $_SESSION['czasObecnosci'] ) > $czasGasniecia) {
  11. $zalogujDB = mysql_query("UPDATE kt_admin SET zalogowany=0 WHERE login='".$_SESSION['login']."'");
  12. $_SESSION['auth'] = FALSE;
  13. } else {
  14. $_SESSION['czasObecnosci'] = time();
  15. }
  16. }
  17. SesFixiHij ();
  18. ?>


--------------------
Go to the top of the page
+Quote Post
MajareQ
post 25.03.2008, 14:43:15
Post #18





Grupa: Zarejestrowani
Postów: 382
Pomógł: 22
Dołączył: 21.05.2007
Skąd: Elbląg

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


na strict data pomogło ustawienie
date_default_timezone_set('Europe/Warsaw');

obecnie mam:

date_default_timezone_set('Europe/Warsaw');
setlocale(LC_ALL, 'pl_PL', 'pl', 'Polish_Poland.28592');

jednak scrict mktime dalej wywala...


data.php

  1. <?php
  2. // funkcja poprawnej daty
  3. function localStrftime($format, $timestamp = 0)
  4. {
  5. if($timestamp == 0)
  6. {
  7. // Sytuacja, gdy czas nie jest podany - używamy aktualnego.
  8. $timestamp = time();
  9. }
  10.  
  11. // Nowy kod - %F dla odmienionej nazwy miesiąca
  12. if(strpos($format, '%F') !== false)
  13. {
  14. $mies = date('m');
  15.  
  16. // odmienianie
  17. switch($mies)
  18. {
  19. case 1:
  20. $mies = 'stycznia';
  21. break;
  22. case 2:
  23. $mies = 'lutego';
  24. break;
  25. case 3:
  26. $mies = 'marca';
  27. break;
  28. case 4:
  29. $mies = 'kwietnia';
  30. break;
  31. case 5:
  32. $mies = 'maja';
  33. break;
  34. case 6:
  35. $mies = 'czerwca';
  36. break;
  37. case 7:
  38. $mies = 'lipca';
  39. break;
  40. case 8:
  41. $mies = 'sierpnia';
  42. break;
  43. case 9:
  44. $mies = 'września';
  45. break;
  46. case 10:
  47. $mies = 'października';
  48. break;
  49. case 11:
  50. $mies = 'listopada';
  51. break;
  52. case 12:
  53. $mies = 'grudnia';
  54. break;
  55. }
  56. // dodawanie formatowania
  57. return strftime(str_replace('%F', $mies, $format), $timestamp);  
  58. }
  59. return strftime($format, $timestamp);  
  60. }
  61. ?>


strona zaczyna mi sie sypać... ja podziekuje juz tych testów...
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: 29.06.2025 - 08:12