Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> bany - warunek
-krizz-
post 5.02.2005, 16:14:43
Post #1





Goście







siema

mam takie pytanko

jeżeli plik z banowanymi IP wygląda tak (bany.txt):

Kod
80.53.58.196
80.53.58.197
80.53.58.198
55.78.32.150


to jak ma wyglądać warunek, żeby pokazywał wpisy lub nie ?

wiem, że ma to być if/else ale nie wiem jak to napisać, jeżeli ip są podane w jakimś pliku
Go to the top of the page
+Quote Post
Vertical
post 5.02.2005, 16:19:22
Post #2





Grupa: Zarejestrowani
Postów: 848
Pomógł: 0
Dołączył: 7.07.2004
Skąd: Wrocław

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


fopen()
fread()
Nie wiem, co jeszcze potrzeba...
Go to the top of the page
+Quote Post
shima
post 5.02.2005, 16:20:47
Post #3





Grupa: Zarejestrowani
Postów: 245
Pomógł: 0
Dołączył: 9.09.2002

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


in_array" title="Zobacz w manualu PHP" target="_manual


--------------------
Nie ma nic stałego prócz zmiany...
Go to the top of the page
+Quote Post
hwao
post 5.02.2005, 16:59:04
Post #4


Developer


Grupa: Moderatorzy
Postów: 2 844
Pomógł: 20
Dołączył: 25.11.2003
Skąd: Olkusz




  1. <?php
  2. $arr = file( 'ten_plik' );
  3. $ip = 'ip goscia'; // z Server sobie wes
  4. if( in_array( $ip, $arr ) )
  5. {
  6.  die( 'masz bana' );
  7. } else {
  8. echo 'nie masz bana...';
  9. }
  10. ?>
Go to the top of the page
+Quote Post
-krizz-
post 6.02.2005, 02:25:47
Post #5





Goście







Cytat(hwao @ 2005-02-05 15:59:04)
  1. <?php
  2. $arr = file( 'ten_plik' );
  3. $ip = 'ip goscia'; // z Server sobie wes
  4. if( in_array( $ip, $arr ) )
  5. {
  6.    die( 'masz bana' );
  7. } else {
  8.   echo 'nie masz bana...';
  9. }
  10. ?>

niestety ale to nie działa sad.gif za każdymrazem wypisuje komunikat - "nie masz bana..." sad.gif
Go to the top of the page
+Quote Post
bela
post 6.02.2005, 02:37:20
Post #6


Administrator PHPedia.pl


Grupa: Developerzy
Postów: 1 102
Pomógł: 2
Dołączył: 14.09.2003

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


$ip = $_SERVER['REMOTE_ADDR']; zmien na to


--------------------
Go to the top of the page
+Quote Post
FiDO
post 6.02.2005, 05:11:36
Post #7





Grupa: Przyjaciele php.pl
Postów: 1 717
Pomógł: 0
Dołączył: 12.06.2002
Skąd: Wolsztyn..... Studia: Zielona Góra

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


Raczej tak:
  1. <?php
  2.  
  3. $arr = array_map('rtrim', file( 'ten_plik' ));
  4. $ip = 'ip goscia'; // z Server sobie wes
  5. if( in_array( $ip, $arr ) )
  6. {
  7.  die( 'masz bana' );
  8. } else {
  9. echo 'nie masz bana...';
  10. }
  11.  
  12. ?>


Dlaczego?

Cytat(Manual(file))
Identical to readfile(), except that file() returns the file in an array. Each element of the array corresponds to a line in the file, with the newline still attached.


--------------------
Brak czasu :/
Go to the top of the page
+Quote Post
-krizz-
post 6.02.2005, 13:40:17
Post #8





Goście







Cytat(FiDO @ 2005-02-06 04:11:36)
Raczej tak:
  1. <?php
  2.  
  3. $arr = array_map('rtrim', file( 'ten_plik' ));
  4. $ip = 'ip goscia'; // z Server sobie wes
  5. if( in_array( $ip, $arr ) )
  6. {
  7.    die( 'masz bana' );
  8. } else {
  9.   echo 'nie masz bana...';
  10. }
  11.  
  12. ?>


Dlaczego?

Cytat(Manual(file))
Identical to readfile(), except that file() returns the file in an array. Each element of the array corresponds to a line in the file, with the newline still attached.

DZIEKI - teraz działa jak nalezy smile.gif

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: 25.07.2025 - 10:07