Jump to content
yo20063

[PHP] Creeaza log file cu vizitatori pe o anumita pagina

Recommended Posts

Posted

Unii dintre voi poate nu aveti acces la apache logs, s-au v-a pus cineva un shell si vreti sa ii aflati ip-ul si nu aveti acces la apache logs.

$time = date("M j G:i:s Y");
$ip = getenv('REMOTE_ADDR');
$userAgent = getenv('HTTP_USER_AGENT');
$referrer = getenv('HTTP_REFERER');
$query = getenv('QUERY_STRING');

$msg = "IP: " . $ip . " TIME: " . $time . " REFERRER: " . $referrer . " SEARCHSTRING: " . $query . " USERAGENT: " . $userAgent;

writeToLogFile($msg);

function writeToLogFile($msg) {
$today = date("Y_m_d");
$logfile = $today."_log.txt";
$dir = 'loguri';
$saveLocation=$dir . '/' . $logfile;
if (!$handle = @fopen($saveLocation, "a")) {
exit;
}
else {
if (@fwrite($handle,"$msg\r\n") === FALSE) {
exit;
}

@fclose($handle);
}
}

Pentru a-l folosi creati un folder cu numele "loguri" in folderul unde este fisierul php pe care vreti sa-l monitorizati, datii write access, apoi in fisierul php de monitorizat introduceti codul de mai sus intre tag-urile "<?php AICI ?>" existente in fisier.

Codul e foarte usor de adaptat in functie de fiecare in parte si de nevoile fiecaruia.

Exemplu log doar cand este accesat un parametru din scriptul php:

Se adauga la inceputul codului de mai sus

if (preg_match("/parametru/i", $_SERVER['REQUEST_URI'])) {

si dupa declararea variabilei

$msg = "IP: " . $ip . " TIME: " . $time . " REFERRER: " . $referrer . " SEARCHSTRING: " . $query . " USERAGENT: " . $userAgent;

se adauga

}

Daca nu intelegeti ceva, PM.

Guest _eusimplu
Posted

Nu inteleg de ce te-ai complicat.


file_put_contents('views.log', print_r($_SERVER,true), FILE_APPEND);

Dar felicitari oricum :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...