By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,028 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,028 IT Pros & Developers. It's quick & easy.

Parse error: syntax error, unexpected '['

P: 1
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $auth = 0;
  3. if(isset($_SERVER['PHP_AUTH_USER']))
  4. {
  5.  
  6.   $uname = $_SERVER['PHP_AUTH_USER'];
  7.   $pwd = $_SERVER['PHP_AUTH_PW'];
  8.  
  9.    $fp = fopen("user.txt","r");
  10.    while($line = fgets($fp))
  11.    {
  12.      $arr = explode(":",$line);
  13.      $un =trim(arr[0]);
  14.      $pw =trim(arr[1]);
  15.  
  16.      if($un == $uname and $pw = $pwd)
  17.      {
  18.  
  19.        auth=1;
  20.     break;
  21.      }
  22.  
  23.    }
  24.  
  25.  }
  26.  
  27.  if($auth == 0)
  28.  header("www-authenticate:Basic realm = \"private area\"");
  29.  
  30.   else
  31.    header("location:welcome.php");
  32. ?>
i am getting this error
Parse error: syntax error, unexpected '[' in C:\xampp\htdocs\auth.php on line 13
Nov 25 '12 #1
Share this Question
Share on Google+
2 Replies


Rabbit
Expert Mod 10K+
P: 12,364
On line 13 and 14, you probably meant to use the variable $arr rather than arr.
Nov 25 '12 #2

solutionwand
P: 16
Hi,
In line 13 and 14.
Relace
$un =trim(arr[0]);
$pw =trim(arr[1]);

with
Expand|Select|Wrap|Line Numbers
  1. $un =trim($arr[0]);
  2.      $pw =trim($arr[1]);
  3.  
Dec 20 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.