load array from file into variables for login ?
I have an external file with some userpreference called userprefs.txt which contains values on several lines (array values).
In another page I have this code below(part of it), trying to get the $realUser
and $realPass
values to be parsed from $userPrefs[0]
and $userPrefs[1]
, seems simple enough, but I cant get it to work. I'm a little confused.
<?php
session_start();
///////////////////////////////////////////////////////////
//read file contents into array, each line in a new element
$filename = "userprefs.txt";
$userPrefs = array();
$file = fopen($filename, "r");
while(!feof($file)) {
//read file line by line into a new array element
$userPrefs[] = fgets($file, 4096);
}
fclose($file);
$realUser = $userPrefs[0];
$realPass = $userPrefs[1];
//if I echo($userPrefs[0]) it displays the value, but when trying to use this to login it fails ...?
//blabla loginscript
if($realUser == blablabla.......and so on..
All works fine, if I define $realUser
and $realPass
with strings; $realUser = 'admin'
$realPass = 'abc'
and I can login. If I echo $realUser
I get the filecontents from the array, but not when trying to login with defining it with value from $userPrefs[0]
.
Is the array read after page has loaded ? and the values not present when post submitting ?
Anyone have any ideas on what's wrong ?
thx!