Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Problem z zapisem adresu IP do pliku
Krastley
post
Post #1





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 22.12.2010

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


Mam taką funkcję:

  1. public static function uniquereader($counter_file) {
  2.  
  3. $user_addr = $_SERVER['REMOTE_ADDR'];
  4.  
  5. if (!is_file($counter_file)) {
  6. $counter_file_stream = fopen($counter_file, 'wb');
  7. fwrite($counter_file_stream, $user_addr);
  8. fclose($counter_file_stream);
  9. }
  10.  
  11. if (!strpos(file_get_contents($counter_file), $user_addr)) {
  12. $counter_file_stream = fopen($counter_file, 'r+b');
  13. fseek($counter_file_stream, -1, SEEK_END);
  14. fwrite($counter_file_stream, "\n".$user_addr);
  15. fclose($counter_file_stream);
  16. }
  17.  
  18. $counter = sizeof(file($counter_file));
  19.  
  20. return $counter;
  21. }


Jak widać, jeżeli nie ma pliku na serwerze, powinien zostać utworzony, a w nim powinien zostać zapisany adres IP. Ale kiedy plik jest tworzony po raz pierwszy, znajduje się w nim coś takiego:


127.0.0.
127.0.0.1


i funkcja zwraca wartość 2. Czy ktoś może mi powiedzieć, dlaczego?
Go to the top of the page
+Quote Post

Posty w temacie


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 Aktualny czas: 21.08.2025 - 23:20