tiy Posted January 15, 2006 Report Share Posted January 15, 2006 Es te iedomajos uzrakstit hostu counteri, it ka ieraksta savu ip 22.11.33.44 tas saglabajas ieksh faila, nomeinu ip uz 22.11.33.43 vai 22.11.31.44, bet vinsh nemaz nesak rakstit faila ip klatm ip ir jau cits neka man, bet ja es samainu 22.14.33.44 vai 21.11.33.44, tad bez problemam visu ierakta. Kapec ta. Var ari biku savadak kads var aprakstit shas darbibas algoritmu $ip=$_SERVER['REMOTE_ADDR']; $path="hits.php"; $list=file($path); $cik=count($list); $x=1; $i=0; while ($i <$cik) { if ($list[$i]==$ip-" "){$x=0;} $i++; } if($x==1){fwrite(fopen($path,'a'),trim($ip)."\n");} echo "Hosts ",count(file($path)); Link to comment Share on other sites More sharing options...
bubu Posted January 15, 2006 Report Share Posted January 15, 2006 Nekā nesapratu no tavas problēmas apraksta. Bet tu labāk pastaāsti, ko šitais tavā kodā nozīmē: if ($list[$i]==$ip-" ") Kā no stringa $ip tu gribi atņemt " " ?? Link to comment Share on other sites More sharing options...
v3rb0 Posted January 15, 2006 Report Share Posted January 15, 2006 pirmais kas nāk prātā $path='hits.php'; $list=file($path); $_SERVER['REMOTE_ADDR'] .= "\n"; if(!in_array($_SERVER['REMOTE_ADDR'],$list)) { $h = fopen($path,'a'); fwrite($h,$_SERVER['REMOTE_ADDR']); fclose($h); } echo 'Hosts '.count($list); Link to comment Share on other sites More sharing options...
tiy Posted January 15, 2006 Author Report Share Posted January 15, 2006 Vispar ar sho rindu ir ta kad pieskir kadam mainigais jebko vinsh pec defalta pieliek speace klat gala, tatad sanak ip ir xxx.xxx.xxx.xxx_ pet ieksh lista ir ir xxx.xxx.xxx.xxx, es atnemu no ip to speace gabalinu if ($list[$i]==$ip-" ") Link to comment Share on other sites More sharing options...
v3rb0 Posted January 15, 2006 Report Share Posted January 15, 2006 hh, tu nu galīgi auzās brauc. ja tā būtu kā saki, tad kāpēc šis nedara to ko stāsti? $s1 = 'abc'; $s2 = 'cba'; $s3 = $s1 . $s2; echo '"'.$s1.'"'; $s1 = $s3 - $s2; echo ' un pec atnemsanas "'.$s1.'"'; Link to comment Share on other sites More sharing options...
tiy Posted January 16, 2006 Author Report Share Posted January 16, 2006 Es paskaidroju bubu to rindinu, tavs source strada ok Thx Link to comment Share on other sites More sharing options...
v3rb0 Posted January 16, 2006 Report Share Posted January 16, 2006 (edited) tas jau ar bija par tavu paskaidrojumu bubu jautajumam, nu nevar no stringa beigam atnemt otru stringu.. ja uzrakstisu "asd" - "fghj" kas sanaks, negativs strings? :) $list[$i]==$ip-" " varetu būt tas pats kas $list[$i]== 0 Edited January 16, 2006 by v3rb0 Link to comment Share on other sites More sharing options...
bubu Posted January 16, 2006 Report Share Posted January 16, 2006 Es paskaidroju bubu to rindinu, tavs source strada ok Thx Tev tak v3rb0 piemēru rādīja.. Kāpēc nepamēģināji. Nu labi moš šis būs skaidrāks: $ip = "123.111.22.11 "; // beigās ir viena atstarpe $ip2 = $ip - " "; // te atņemam tavu atstarpi echo "Tagad ip2 = <", $ip2, ">"; Kā tu domā, ko izvadīs? Un pamēģini palaist un paskatīties, nevis tikai pateikt, ko tu domā :) Link to comment Share on other sites More sharing options...
Grey_Wolf Posted January 16, 2006 Report Share Posted January 16, 2006 atstarpju likvideeshanai ir taada lieta kaa triim() kas novaac visu leiko nosakuma un beigaam - atstarpes un /n /r Link to comment Share on other sites More sharing options...
Recommended Posts