Hi all, I have a simple logging script that is giving me trouble. It gives me the Parse error: syntax error, unexpected T_VARIABLE in logging.php on line 13. I searched for missing brackets, colons, parenthesis and found nothing. I could really use some help. here is the code. <?php //ASSIGN THE BASIC VARIABLES FOR YOUR VISITOR $time = date("M j G:i:s Y"); $ip = getenv('REMOTE_ADDR'); $userAgent = getenv('HTTP_USER_AGENT'); $query = getenv('QUERY_STRING'); //COMBINE VARS INTO OUR LOG ENTRY $msg = " TIME: " . $time . " USERAGENT: " . $userAgent. " USER-QUERY: " . $query. "IP: " . $ip; //CALL THE CENTRAL FUNCTION TO WRITE TO THE LOG FILE logAction($msg); function logAction($msg) { $today = date("Y_m_d"); $logfile = $today."_log.txt"; $dir = 'logs'; $saveLocation=$dir . '/' . $logfile; if (!$handle = @fopen($saveLocation, "a")) { exit; } else { if(@fwrite($handle,"$msg\r\n")===FALSE) { exit; } @fclose($handle); } } ?> PHP: Thanks in advance all.
The first thing that jumps out at me is that you define your function after you use it. should be the other way around.
Oh yeah, i noticed that after I posted. But it did not do the trick. It just moved the error line. I checked the lines before and after. I've noticed most times with a t_variable it's a missing colon, bracket, period or something. But I cant seem to find anything missing. rewrote it line by line several times. Thought it was the my format for the date. but nothing works.
Have you checked whether there are any invalid characters in it. If you are using Netbeans, it might add some I think. Say, for tabs ! So check that.