Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> bany - warunek
-krizz-
post
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
 
Start new topic
Odpowiedzi (1 - 7)
Vertical
post
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
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
Go to the top of the page
+Quote Post
hwao
post
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
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 (IMG:http://forum.php.pl/style_emoticons/default/sad.gif) za każdymrazem wypisuje komunikat - "nie masz bana..." (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)
Go to the top of the page
+Quote Post
bela
post
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
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.
Go to the top of the page
+Quote Post
-krizz-
post
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 (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

pozdrawiam
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 22.08.2025 - 16:27