Go4Expert

Go4Expert (http://www.go4expert.com/)
-   PHP (http://www.go4expert.com/articles/php-tutorials/)
-   -   Login and Logout using Sessions and Cookies (http://www.go4expert.com/articles/login-logout-using-sessions-cookies-t361/)

ted_chou12 1Dec2006 14:54

Re: Login and Logout using Sessions and Cookies
 
can you write an eg. and send the file to me with zip?

ted_chou12 1Dec2006 15:17

Re: Login and Logout using Sessions and Cookies
 
i just want a simple example. With the username and age in the text file and the codes that you have to include in the php page, thanks so much.

ted_chou12 2Dec2006 22:36

Re: Login and Logout using Sessions and Cookies
 
spiderman, you not there...? HELP ASAP

pradeep 3Dec2006 01:08

Re: Login and Logout using Sessions and Cookies
 
Try this out, hope you got the point!

Code: PHP

<?
/*
**  Our text file's format is values separated by #
**  And example entry would look like this
**  pradeep#myPassword#Kolkata
*/


$TEXT_FILE = 'data.txt';
$aData = @file($TEXT_FILE); // collect all data into an array

// Dummy data
$user = 'pradeep';
$pwd = 'g4e';

foreach($aData as $v)
{
    list($u,$p,$c) = explode("#",$v); // split up the differnt parts of the data

    if($u == $user && $p == $pwd)
    {
        print "Matched";
        break;
    }
}

?>


Sample text file:
Code:

pradeep#g4e#Kolkata
shabbir#G4E#Kolkata
manindar#ABC#Mumbai


ted_chou12 3Dec2006 01:54

Re: Login and Logout using Sessions and Cookies
 
hey, thanks a lot. it finally worked :) :cool:

ted_chou12 3Dec2006 21:37

Re: Login and Logout using Sessions and Cookies
 
hi, again.
As i got this to work, things got more complicated, here
PHP Code:

<?php
$bData 
= @file("../admin/log_files/members_list.txt"); 
foreach(
$bData as $w){list($username1,$username2,$username3) = explode(":",$w);
$aData = @file("../admin/log_files/members_list.txt"); // collect all data into an array
foreach($aData as $v){list($username,$email,$time) = explode(":",$v); // split up the differnt parts of the data?
echo "<table><tr><td><font face=\"arial\" size=5><b>Last Modification:</b></td><td>$username</td></tr></font>";
echo 
"<tr><td><font face=\"arial\" size=5><b>Name:</b></td><td>$email</td></tr></font>";
echo 
"<tr><td><font face=\"arial\" size=5><b>Gender:</b></td><td>$time</td></tr></font></table>";}}
?>

Now I have two layers, I separated each username with # and the user data with :, and i want to ask if the "$username1,$username2,$username3..." part streches to infinity, what shall i put in? :confused:

pradeep 4Dec2006 10:14

Re: Login and Logout using Sessions and Cookies
 
Code: PHP

<?
// Simple just do this
$aUserList = explode("#",$v);
// This returns an array
?>


ted_chou12 4Dec2006 14:50

Re: Login and Logout using Sessions and Cookies
 
oh, so you dont separte the data?

ted_chou12 4Dec2006 15:01

Re: Login and Logout using Sessions and Cookies
 
Can you give me another example please?
I cant get it to work
ps. please do include the txt file as well, a big "pre"thanks!

cyberience 5Dec2006 12:51

Re: Login and Logout using Sessions and Cookies
 
Good script, got a question though, if we have multiple servers with various configurations in load balancing, and we try to maintain a session, that session will be lost when either round robin on next connection is in effect, so sessions is not an option due to persistence issues, and we don't want to enable persistence through the firewall, as it is not under our control. so we would need to rely on the cookie credentials for every page call to validate the user log in!
also, due to distributed database architecture, we can not maintain credentials in the database either. So we would need to take the cookie credentials and validate on every page. and pass other data via http header.

What is the modification to this script if sessions are not available, but still maintain security?


All times are GMT +5.5. The time now is 10:49.