Erm Once your member is registered you must somehow remember users data. Instead of using a file (because really hards to handle) you can use mySQL.
For example person A is registered with password B. You can INSERT him to database. But wait, where? So you need a table in your mysql database.
You can create something like: members and create some fields.
member_name, member_password. Ok you can store your details into it.
Ok now we table with users data.
Now we want to make user profile. We can easily add more field to member.
For more advanced system we would need to put something unique so we can get data which belongs to person A from other tables. For this we create one more field (it will be PRIMARY (important one)) which would have unique ID. It's easy because mysql has auto_increment option so that field will increment automaticaly. Then person A is registered he will get id 1. Another person 2 and etc.
(i forgot to mention that that field can be called id_member)
So we now got.
id_member, member_name, member_password..........
1, A, B
How to detect if the right one is logged in?
So then member fills his name and password, you would need to check if there's ANY members which have that name and password. If you find someone then data is correct and you can use his name and add it to session. ($_SESSION) So now he's registered and you have a member.
I will share my php script with you.
php
function login2() {
$username = $_POST['username'];
$password = $_POST['password'];
if($username == mysql_real_escape_string($username)) {
$password = sha1(md5(sha1($username.$password.'5KSK5RIWXJT3OVFN14WQSHXLWZDKR58ZP7GTY5V5')));
$result = mysql_query("SELECT id_member FROM members where is_activated='1' AND real_name='$username' AND password='$password'");
if(mysql_num_rows($result) !== 0) {
$row = mysql_fetch_object($result);
$_SESSION['id_member'] = $row->id_member;
$_SESSION['password_hash'] = $password;
if($_POST['remember_me']) {
$time = 60*60*24*12 + time();
$id = $row->id_member;
setcookie("_id", $id, strtotime("+365 days"));
setcookie("_hash", $password, strtotime("+365 days"));
}
}
}
loadLanguage('login');
loadTemplate('login');
}
This script is only example and won't work properly because you will be missing functions and mysql table.
So I get from form username and password. Escape bad characters. (google SQL injection for more information why). Encode my password with md5 and sha1 functions so I can't see password directly. From password B it will become something like 'fdjeswifrewif546f65e7g8'. Mysql_query - i ask for something from table then check if someone found
if(mysql_num_rows($result) !== 0)
if not 0 rows of data found then this one exists, we can set session.
If you don't understand something then go to php.net and in search box type the function or look at w3schools.
Read this:
http://www.w3schools.com/php/php_forms.asp So now you will know what $_POST or $_GET does.
To connect to mysql
http://www.w3schools.com/php/php_mysql_connect.aspThis post has been edited by Dancia: 16 Jul, 2008 - 09:37 AM