help debug a php page
<?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);
?>
if i try to open this php it gives me a server error
HTTP Error 500 (Internal Server Error): An unexpected conditio开发者_如何学JAVAn was encountered while the server was attempting to fulfill the request.
and i have also tested it follow the steps here, but it didn't produce any log message
"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.
I can't answer your question about debugging and logging but for what it's worth. Your error is on line 6. Replace it by following:
if(!empty($_SERVER['QUERY_STRING']))
$page .= $_SERVER['QUERY_STRING'];
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
精彩评论