Вопрос

<?php
error_reporting(E_ALL);
// Getting the information 
$ipaddress = $_SERVER['REMOTE_ADDR']; 
$page = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}";
if(!empty($_SERVER['QUERY_STRING']) $page .= $_SERVER['QUERY_STRING'];
$referrer = $_SERVER['HTTP_REFERER'];
$datetime = mktime(); 
$useragent = $_SERVER['HTTP_USER_AGENT'];
$remotehost = getHostByAddr($ipaddress);

// Create log line
$logline = $ipaddress . '|' . $referrer . '|' . $datetime . '|' . $useragent . '|' . $remotehost . '|' . $page . "\n"; 
echo $logline;
// Write to log file: 
//$logfile = 'logfile.txt';
$logfile = '/home/www/agro-dive.onlinewebshop.net/logfile.txt';

// Open the log file in "Append" mode 
if (!$handle = fopen($logfile, 'a+')) {
    die("Failed to open log file"); 
} 

// Write $logline to our logfile. 
if (fwrite($handle, $logline) == FALSE) {
    die("Failed to write to log file"); 
} 

fclose($handle);  

?>
.

Если я попытаюсь открыть этот php, это дает мне ошибку сервера

HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.
.

И я также проверил, он следуют за шагами Здесь , ноЭто не дало никакого журнала сообщения

Это было полезно?

Решение

Я не могу ответить на ваш вопрос о отладке и регистрации, но для того, что это стоит.Ваша ошибка находится в строке 6. Замените его, следуя:

if(!empty($_SERVER['QUERY_STRING']))
    $page .= $_SERVER['QUERY_STRING'];
.

Другие советы

"server error" means "you have to look into servers error_log for the particular error message".

Debugging stands for reading error messages, not watching the code nor guessing.

BobDcoder here! 2019 update

While this is marked as solved/accepted/whatever, the answer appears to be the wrong fix according to the documentation. Many newbies and seasoned coders alike believe this to be a ternary if statement. ( however you spell ternary,lol.) but the original poster (op) states differently!

while I could be wrong I think the problem is:

$page = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}"; 
$page .= iif(!empty($_SERVER['QUERY_STRING']), "?{$_SERVER['QUERY_STRING']}", ""); 

(which $page is an append to on the second line of code.)

many newbies and seasoned coders alike believe this to be a ternary if statement. ( however you spell ternary,lol.)

In the original documentation, the OP states that this is a function call. https://www.go4expert.com/articles/track-visitors-using-php-t195/

To quote the OP in the documentation........ "Note: I used a function in the above example called iif(). You can get this function at http://www.phpit.net/code/iif-function."

Sadly the link to the iif() function is dead, so maybe someone has the old code for this function and can post it here or at some other repository.

While the other correction above may allow the code to test true or false and fall through and process the rest of the code, I think the OP may have used it "iif() for other purposes as a function (bad programing choice of a function call).

// Write to log file: 
//$logfile = 'logfile.txt';
$logfile = 'log.log';

where log.log is your log file

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top