PDA

View Full Version : Adding PHP Login to Admin Page



Pherank
March 5th, 2008, 10:03 PM
I made some modifications to the following script:

http://www.php-editors.com/articles/php_textfile.php

Now when a user is added to the textfile, the password is encrypted. Now I want to create a login page that accesses this textfile and looks for a match. I have a PHP script that is similar (login.php), but needs to be modified to work with the data as written by the admin page. Can someone take a look and tell me how to access the textfile data by $clientname (I think).

PS: I guess the title of this thread should be "Adding a PHP Login page (already have Admin page)"

Pherank
March 6th, 2008, 05:42 PM
I decided to break things up and do this one piece at a time. If I have a textfile (users.txt) with the following arrays written to it -



[Cracker Jack]
clientname=Cracker Jack
password=swordfish

[PanAm]
clientname=PanAm
password=blowfish
How do I access this data with PHP? The first question is how to loop through all the data and display it to screen. The second would be, if the user enters a "clientname" and "password" in a form, how to find a match (or no match) in the textfield arrays?

Here is some code to I'm using to try to loop through the array data - not yet working right:



<?php
echo "<h1>Manual access to each element from associative array</h1>";

$fp = fopen ( 'users.txt', 'r' );
while ( $line = fgetcsv ($fp, 100, "\t")) {

for ($row = 0; $row < 2; $row++)
{
echo $line[$row]["clientname"]." password: ".$line[$row]["password"];
echo "<br />";
}
}

echo "<h1>Using foreach loop to display elements</h1>";

echo "<ol>";
for ($row = 0; $row < 2; $row++)
{
echo "<li><b>The row number $row</b>";
echo "<ul>";

foreach($line[$row] as $key => $value)
{
echo "<li>".$value."</li>";
}

echo "</ul>";
echo "</li>";
}
echo "</ol>";
?>