Jump to content

Recall Stored Data for login


TheJoey

Recommended Posts

Here is my code so far

<?php

$email = $_POST['email'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$age = $_POST['age'];
$address = $_POST['address'];
$city = $_POST['city'];

$fp = fopen("data.txt","a");

if(!$fp) {
    echo 'Error: Cannot open file.';
    exit;
}

fwrite($fp, $email."||".$fname."||".$lname."||".$age."||".$address."||".$city."\r\n");

fclose($fp);
?>

 

im having real trouble reclaiming that text for a login script.

Could anyone start me off.

Link to comment
https://forums.phpfreaks.com/topic/172568-recall-stored-data-for-login/
Share on other sites

I'd use file instead. file returns an array of lines. Then you can use a loop to easily check each line.

 

$lines = file('data.txt');

foreach($lines as $line)
{
    $bits = explode('||', $line);
    echo '<pre>'.print_r($bits, true).'</pre>';
}

well i was thinking of going to make everyone [0] a username and [1] a password from my stored information. How would i go about doing so?

Array
(
    [0] => joe@joe
    [1] => joe
    [2] => joe
    [3] => 21
    [4] => as
    [5] => as

)

Array
(
    [0] => joe@joe
    [1] => joe
    [2] => joe
    [3] => 21
    [4] => as
    [5] => as

)

 

so [0] => joe@joe would be my username and

    [1] =>joe would be my password

<?php
$userinfo = file("data.txt");

   echo '<table>';

foreach($userinfo as $key => $val) 
{
   $data[$key] = explode("||", $val);
}

for($k = 0; $k < sizeof($userinfo); $k++) 
{ 
   echo '<tr><td>Username:</td><td>'.$data[$k][0].'</td></tr>';
   echo '<tr><td>Password:</td><td>'.$data[$k][1].'</td></tr>';
   echo '<tr><td colspan=2> </td></tr>';
}

   echo '</table>';
?>

 

This is displaying it a little easier to explain i think.

Username: joe@joe

Password: joe

Username: joe@joe

Password: joe

 

was thinking something like this for the form.

Having trouble using the code you gave me to proccess the login

echo '<table>
<tr><td>Username<br>
<form action="read3.php" method="post">
<input name="username" type="text"></td></tr>
<tr><td>Password<br>
<input name="password" type="password"></td></tr>
<tr><td><input value="Submit" type="submit"></td></tr>
<tr><td><a href="register/index.php">Register</a></td></tr>
</table>';

was thinking something like this for the form.

Having trouble using the code you gave me to proccess the login

echo '<table>
<tr><td>Username<br>
<form action="read3.php" method="post">
<input name="username" type="text"></td></tr>
<tr><td>Password<br>
<input name="password" type="password"></td></tr>
<tr><td><input value="Submit" type="submit"></td></tr>
<tr><td><a href="register/index.php">Register</a></td></tr>
</table>';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.