Parse error: syntax error, unexpected T_VARIABLE line 13

Discussion in 'PHP' started by dcjokerbx, May 10, 2012.

  1. #1
    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.
     
    Last edited: May 10, 2012
    dcjokerbx, May 10, 2012 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,899
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    The first thing that jumps out at me is that you define your function after you use it. should be the other way around.
     
    sarahk, May 10, 2012 IP
  3. dcjokerbx

    dcjokerbx Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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.
     
    dcjokerbx, May 10, 2012 IP
  4. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #4
    It compiled fine for me. What version of PHP are you running?
     
    Alex Roxon, May 10, 2012 IP
  5. dcjokerbx

    dcjokerbx Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I'm running [FONT=arial, helvetica, clean, sans-serif]version [/FONT]5.2.12
     
    dcjokerbx, May 10, 2012 IP
  6. akhileshbc

    akhileshbc Active Member

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    5
    Trophy Points:
    75
    #6
    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.
     
    akhileshbc, May 27, 2012 IP
  7. kbduvall

    kbduvall Peon

    Messages:
    71
    Likes Received:
    3
    Best Answers:
    4
    Trophy Points:
    0
    #7
    Are you including/requiring any PHP files before this one?
     
    kbduvall, May 28, 2012 IP