Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading file

Status
Not open for further replies.

jartse

Programmer
Apr 10, 2002
15
FI
so i want to read text file and password have to match with user. if open tset.php>>>
it read 123.txt file and check password and if is right
it prints first name and lastname

TEST.PHP
************
<?PHP
$dataname = $HTTP_GET_VARS['u'+'.txt'];
$pass = $HTTP_GET_VARS['p'];

if(file_exists($dataname))
{
$data = fopen($dataname, &quot;r&quot;);
if ($data)
{
$line1 = trim(fgets($data, 255));
$line2 = trim(fgets($data, 255));
$line3 = trim(fgets($data, 255));
fclose($data);
}
}
if ($pass = $line1)
{
echo &quot;$line2&quot;;
}
echo &quot;wrong password&quot;;

?>
*************

123.TXT
*************
qwerty
jack
dalton
*************
 
just a quick note
if condition needs a double = sign

ie

if ($pass == $line1)
.......


spookie

 
yes,

if you don't place the double =, instead of comparing, it sets the var $pass to the value of $line. The if only fails when $line is 0, null or false. Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
thanks
i have correct this code litle it works good if i use
$dataname=&quot;123.txt&quot;;
but i want to give filename on address line like this

test.php?u=123&p=qwerty so if i want read file 123.txt

test.php?u=124&p=qwerty so if i want read file 124.txt


<?PHP
$dataname = $HTTP_GET_VARS['u'+.txt];
$pass = $HTTP_GET_VARS['p'];
if(file_exists($dataname))
{
$data = fopen($dataname, &quot;r&quot;);
if ($data)
{
$line1 = trim(fgets($data, 255));
$line2 = trim(fgets($data, 255));
$line3 = trim(fgets($data, 255));
fclose($data);
if ($pass==$line1)
{
echo $line2;
echo &quot;<br>&quot;;
echo $line3;
}
else
{
echo &quot;wrong password&quot;;
}
}
}
else
{
echo &quot;no filename&quot;;
}
?>



123.TXT
*************
qwerty
jack
dalton
*************


124.txt
*************
qwerty
Agnus
MacGyver
*************

 
why not as simple as

<?
if (!$array=file($HTTP_GET_VARS.&quot;.url&quot;)){
// No file by that name
}
else{
// $file[0] has the password
// $file[1] has the 1st name
// $file[2] has the last name
}

hope this helps you out.

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top