Tvinky Posted October 27, 2005 Report Share Posted October 27, 2005 Situacija tada, man vajag salidzinat ip adresi ar adresem kuras ir ieksh txt faila. Skripts ir tads: <?php $fo = fopen('users.txt', 'a+'); $user_ip = $_SERVER['REMOTE_ADDR']; $f = file('users.txt'); $cnt = count($f); for ($i=0; $i<$cnt; $i++) { if ($user_ip == $f[$i]) { echo "Tads ip jau ir"; } else { fwrite($fo, "$user_ip\r\n"); } echo $i++; } ?> Nu vot, un situacija tada, ka ja fails txt ir tuksh, vins neka neraksta. Ja faila ir kaut kads burts, tad vins sak localhost adresi rakstit 127.0.0.1 Ghm, un nemaz nesaka ka tads ip jau ir, tik atkarto un atkarto. P.S Esmu iesacejs, tejkanna :) Ja kads var paldizet, tad ar tadiem konkretakiem piemeriem, jo pagruti tadiem iesacejiem kaut ko saprast stipri sarezgitu. Paldies! Link to comment Share on other sites More sharing options...
[Ya] Posted October 27, 2005 Report Share Posted October 27, 2005 to visu var saīsināt ... $flag=(filesize('users.txt')>0 ? "a+" : "w+"); foreach(file('users.txt') as $userip) { if($_SERVER['REMOTE_ADDR']==trim($userip)) { $exists=true; break; } else { $exists=false; } } if(!$exists) { $f=fopen("users.txt",$flag); fwrite($f,$_SERVER['REMOTE_ADDR']); fclose($f); } else { echo "Ir Jau tāc IP"; } kļūdas tavā kodā, cikls jau skaita $i++; bet tu vēlreiz pieskaiti tādad pa vienu pārbaudi tu saskaiti $i+=2; tātad 2,4,6,8...... otrkārt, tu par katru pārbaudes reizi pievieno IP, un ja tas ip ir iekšā, tad to reizi izlaiž Link to comment Share on other sites More sharing options...
v3rb0 Posted October 27, 2005 Report Share Posted October 27, 2005 eh, arii uzrakstiiju :) nu lab, taapa iespamosu lai arii atbildeets. $fo = fopen('users.txt', 'a+'); $f = file('users.txt'); $cnt = count($f); $add = true; for ($i=0; $i<$cnt; $i++) if ($_SERVER['REMOTE_ADDR'] == trim($f[$i])) { $add = false; break; } if($add) fwrite($fo, $_SERVER['REMOTE_ADDR']."\r\n"); fclose($fo); Link to comment Share on other sites More sharing options...
Tvinky Posted October 27, 2005 Author Report Share Posted October 27, 2005 Liels paldies, jumsejos viss strada perfekti :) Es vnks rakstu, skriptu lai noteiktu cik cilveku ir saita online :) Tagad vel jasataisa, lai ik pec 5min parbauda, ja nav aktivs tad ip izdzesh no saraksta. Ir kadi ieteikumi, ka to izdarit? P.S Vel viens jautajums, jums nav kadu e-booku prieksh iesacejiem? Sausmig gruti man iet ;( Link to comment Share on other sites More sharing options...
[Ya] Posted October 27, 2005 Report Share Posted October 27, 2005 http://lv.php.net Link to comment Share on other sites More sharing options...
Tvinky Posted October 27, 2005 Author Report Share Posted October 27, 2005 Uz turieni mani jau sutija vairakas reizes. Bet vai tas ir iesacejiem? Cik esmu tur bijis iekshsa lasijis - iebraukt nu nekadigi nekama nevaru... Link to comment Share on other sites More sharing options...
[Ya] Posted October 27, 2005 Report Share Posted October 27, 2005 Uz turieni mani jau sutija vairakas reizes. Bet vai tas ir iesacejiem? Cik esmu tur bijis iekshsa lasijis - iebraukt nu nekadigi nekama nevaru... 25613[/snapback] tur viss ir ļoti saprotams, vajag lasīt un domāt līdzi ... ja pavirši ieskatās tad ir kā ir, palasi arī komentārus tur šad tad kautko gatavu jau iemet .... Link to comment Share on other sites More sharing options...
Tvinky Posted October 27, 2005 Author Report Share Posted October 27, 2005 Man petit atsevishki tas funkcijas? Ar kuram man sakt? Un, ka man zinat ar kuram sakt ? Link to comment Share on other sites More sharing options...
[Ya] Posted October 27, 2005 Report Share Posted October 27, 2005 Man petit atsevishki tas funkcijas? Ar kuram man sakt? Un, ka man zinat ar kuram sakt ? 25615[/snapback] skatoties ko tev tieshi vajag, ja zini anglju valodu tad nekadu problemu nav... Link to comment Share on other sites More sharing options...
Tvinky Posted October 27, 2005 Author Report Share Posted October 27, 2005 Perfekti nē - tur tak var uzlikt krievu valodu arī :) Es abās palasuīju. Heh, tomēr noderīga informācija. Paldies visiem. Link to comment Share on other sites More sharing options...
v3rb0 Posted October 27, 2005 Report Share Posted October 27, 2005 1mais jautaajums - vai esi kaut ko programeejis citaas valodas? ja nee, tad jaasaak ar to ka jaaiemaacaas kas ir mainiigie, cikli, masiivi, object utt. ja tas viss ir +/- skaidrs, tad iesaakumam neko vairaak kaa galvu un zinaat kaa kaut ko atrast php manuaalii nevajag. Link to comment Share on other sites More sharing options...
blackhalt Posted October 27, 2005 Report Share Posted October 27, 2005 Perfekti nē - tur tak var uzlikt krievu valodu arī :) Es abās palasuīju. Heh, tomēr noderīga informācija. Paldies visiem. 25628[/snapback] Uz windows šito ņem: http://lv.php.net/docs-echm.php Link to comment Share on other sites More sharing options...
[Ya] Posted October 27, 2005 Report Share Posted October 27, 2005 Uz windows šito ņem:http://lv.php.net/docs-echm.php 25642[/snapback] Offtopiks ... hmm tavs nix kautkur dzirdeec :) Link to comment Share on other sites More sharing options...
Roze Posted October 27, 2005 Report Share Posted October 27, 2005 eh, arii uzrakstiiju :) nu lab, taapa iespamosu lai arii atbildeets. $fo = fopen('users.txt', 'a+'); $f = file('users.txt'); $cnt = count($f); $add = true; for ($i=0; $i<$cnt; $i++) if ($_SERVER['REMOTE_ADDR'] == trim($f[$i])) { $add = false; break; } if($add) fwrite($fo, $_SERVER['REMOTE_ADDR']."\r\n"); fclose($fo); 25603[/snapback] A man labāk patiktu šādi.. $in = @file('users.txt'); if(@in_array($_SERVER['REMOTE_ADDR'] ,$in)) { echo 'Ip ir'; } else { $out = fopen('users.txt',a); fwrite($out,$_SERVER['REMOTE_ADDR']."\r\n"); fclose($out); } Proti wraitoshanai failu atveram tikai tad kad tas vajadzīgs.. bez liekiem mainīgajiem. Link to comment Share on other sites More sharing options...
bubu Posted October 27, 2005 Report Share Posted October 27, 2005 in_array() tādā tīrā veidā uz ar file() iegūto masīvu nedarbosies. Tur būs \n simbols beigās katrai rindai. Ir jāmeklē $ip."\n" vai arī jataisa trim maps uz visām masīva vērtībām pirms meklēšanas. Bet visā visumā Rozes iedotais koda is way to go! Gan ātrdarbības dēļ, gan koda smukuma dēļ ;) Link to comment Share on other sites More sharing options...
Recommended Posts