Parse error: syntax error, unexpected '['

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vivekphp
    New Member
    • Nov 2012
    • 1

    Parse error: syntax error, unexpected '['

    Code:
    <?php
    $auth = 0;
    if(isset($_SERVER['PHP_AUTH_USER']))
    {
    
      $uname = $_SERVER['PHP_AUTH_USER'];
      $pwd = $_SERVER['PHP_AUTH_PW'];
    
       $fp = fopen("user.txt","r");
       while($line = fgets($fp))
       {
         $arr = explode(":",$line);
         $un =trim(arr[0]);
         $pw =trim(arr[1]);
    
         if($un == $uname and $pw = $pwd)
         {
    
           auth=1;
    	break;
         }
    
       }
      
     }
    
     if($auth == 0)
     header("www-authenticate:Basic realm = \"private area\"");
    
      else
       header("location:welcome.php");
    ?>
    i am getting this error
    Parse error: syntax error, unexpected '[' in C:\xampp\htdocs \auth.php on line 13
    Last edited by Rabbit; Nov 25 '12, 09:01 PM. Reason: Please use code tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    On line 13 and 14, you probably meant to use the variable $arr rather than arr.

    Comment

    • solutionwand
      New Member
      • Dec 2012
      • 16

      #3
      Hi,
      In line 13 and 14.
      Relace
      $un =trim(arr[0]);
      $pw =trim(arr[1]);

      with
      Code:
      $un =trim($arr[0]);
           $pw =trim($arr[1]);

      Comment

      Working...