Twey: How come, it's not in the right forum?
Everyone who sees this post: If you want to know how to use it of why to use it, let me show you a demonstration:
Suppose, you're creating a login system and you need a flat-file text database in the registration you simply append the data to the file users.txt, something like this:
Code:
<?php exit();?>
//userid generated from uniqid() or some other techniques
someuser:userid,password
someotheruser:hisid,password
the userdata.txt file:
Code:
<?php exit();?>
userid:email,someotherdata
hisid:email,someotherdata
You've the following code to read the user data/login the user:
PHP Code:
<?php
session_start();
$userlist = newfile("users.txt", ":");
$userdata = newfile("userdata.txt", ":");
list($id, $password) = explode(",",$userlist[$_POST["username"]);
if(isset($userlist[$_POST["username"]]) && $password == $_POST["password"]){
echo "Hello ".$_POST["username"]."<br>";
echo "Your email is $userdata[$id]";
$_SESSION["user"] = $id;
}
?>
In this way you can use only the id to find out anything about the user(something similar to relational databases) but it also gives you more power to update fields, I'll write about updating fields later(I am in school now and I even live coded the above scripts so they might not work, I will post a working version as soon as I get home(hopefully)).
Bookmarks