sayed Posted December 14, 2004 Report Share Posted December 14, 2004 (edited) Nu esu saja lietaa veel iesacejs, bet gribeetos savaa HP ielikt skriptinju kas paradis cik cilveki apluko manu HP Vai kads varetu pateikt kadu Edited December 14, 2004 by sayed Link to comment Share on other sites More sharing options...
Kaklz Posted December 14, 2004 Report Share Posted December 14, 2004 (edited) Nez kāpēc neļauj labot iepriekšējo postu. šite mazliet saprotamāk, bez iezīmju kļūdām: <?php echo rand(1,20); ?> Bet ja nopietni, tad doma varētu būt aptuveni šāda: Saglabājam kādā vietiņā (failā vai datubāzē), kad un kāda IP adrese ir apmeklējusi mūsu lapu, pie katras lapas ielādes aplūkojam failiņu un izdzēšam ierakstus, kas vecāki par kādu noteiktu laika periodu. Parasti mājas lapās norāda, ka x apmeklētāji ir bijuši pēdējo y minūšu laikā. Tātad, PHP kods: // atceries par x apmekleetaajiem peedeejo y minuushu laikaa ? $y = 15; // sagatavojam ierakstu par apmekleejumu - ip adrese un shiibriizha laiks $visit = $_SERVER['REMOTE_ADDR'] . '|' . date('Y-m-d H:i:s') . "\n"; // veram valjaa failu $fp = fopen('fails', 'a'); // rakstaam apmekleejumu failaa fwrite($fp, $visit); // veram ciet failu fclose($fp); // lasaam visus datus no faila ieksh allVisits masiiva $allVisits = file('fails'); // inicializeejam masiivu $currentVisitors = array(); // ejam cauri visiem datiem foreach ($allVisits as $visitItem){ // sadalaam katru rindinju pa sastaavdaljaam - IP adrese un apmekleejuma laiks list($ip, $time) = explode('|', $visitItem); // ja ir peedeejo y minuushu laikaa, tad if (strtotime($time) + $y * 60 > strtotime(date('Y-m-d H:i:s'))){ // atceramies sho apmekleejumu $currentVisitors[$ip] = $time; } } // veram valjaa failu $fp = fopen('fails', 'w'); // ejam cauri visiem apstraadaatajiem datiem foreach ($currentVisitors as $ip => $time){ // veidojam rindinju $visit = $ip . '|' . $time . "\n"; // rakstaam failaa fwrite($fp, $visit); } // veram ciet failu fclose($fp); // galu galaa, izdrukaajam aaraa, cik tad nu mums iisti ir bijushi tie apmekleetaaji peedeejo y minuushu laikaa. echo count($currentVisitors); njem par labu, testeejis neesmu, vajadzeetu straadaat. Edited December 14, 2004 by Kaklz Link to comment Share on other sites More sharing options...
sayed Posted December 14, 2004 Author Report Share Posted December 14, 2004 (edited) ir ir samudiijos meisteribaa Edited December 14, 2004 by sayed Link to comment Share on other sites More sharing options...
Venom Posted December 14, 2004 Report Share Posted December 14, 2004 $onl=180;//seconds 2 be considered online $period='/tmp/'.floor(time()/$onl).'.onl'; $tmp=@file($period); if (!$tmp) $tmp=array(); $ip=(isset($_SERVER['REMOTE_ADDR'])?$_SERVER['REMOTE_ADDR']:''). (isset($_SERVER['HTTP_X_FORWARDED_FOR'])?';'.$_SERVER['HTTP_X_FORWARDED_FOR']:''). (isset($_SERVER['HTTP_CLIENT_IP'])?';'.$_SERVER['HTTP_CLIENT_IP']:'')."\n"; if (!in_array($ip,$tmp)) { $fh=fopen($period,'a'); flock($fh,LOCK_EX); fwrite($tmpfile,$ip); flock($fp,LOCK_UN); fclose($fh); $tmp[]=$ip; } echo count($tmp).' apmekletajs lapa pedejas '.$onl.' sekundes'; Link to comment Share on other sites More sharing options...
raivis Posted December 14, 2004 Report Share Posted December 14, 2004 (edited) Send to Kaklz.. --- kļūda: Warning: strtotime() [function.strtotime]: Called with an empty time parameter. in c:\wamp\www\scripts\online.php on line 21 Warning: strtotime() [function.strtotime]: Called with an empty time parameter. in c:\wamp\www\scripts\online.php on line 21 rindiņā: if (strtotime($time) + $y * 60 > strtotime(date('Y-m-d H:i:s'))){ Edited December 14, 2004 by raivis Link to comment Share on other sites More sharing options...
Recommended Posts