Login Form ---- Help Me

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
easyredboy
Forum Newbie
Posts: 9
Joined: Tue Feb 26, 2008 12:18 am

Login Form ---- Help Me

Post by easyredboy »

I want to facilate users by letting them make new membership.
And alsso want them to login to access differnt things in my website..
Can Anyone Help me in doing this..
:(
Pls gimme comments
:banghead:
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Login Form ---- Help Me

Post by Christopher »

That is a very big subject. Can you be more specific and post the code you currently have.
(#10850)
easyredboy
Forum Newbie
Posts: 9
Joined: Tue Feb 26, 2008 12:18 am

Re: Login Form ---- Help Me

Post by easyredboy »

Pls only
just a txt file in username with all username(i can)
and a txt file in password with all password(i can)
a form in html (i can do)
php code(the worst thing, all mistake)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Login Form ---- Help Me

Post by Christopher »

Post your code.
(#10850)
easyredboy
Forum Newbie
Posts: 9
Joined: Tue Feb 26, 2008 12:18 am

Re: Login Form ---- Help Me

Post by easyredboy »

easyredboy wrote:I want to facilate users by letting them make new membership.
And alsso want them to login to access differnt things in my website..
Can Anyone Help me in doing this..
:(
Pls gimme comments
:banghead:
easyredboy
Forum Newbie
Posts: 9
Joined: Tue Feb 26, 2008 12:18 am

Re: Login Form ---- Help Me

Post by easyredboy »

THE cODE IS HERE
only 4 one user now

Code: Select all

<?
$username=$_POST["username"];
$password=$_POST["password"];
$handle = fopen("username.txt", "r");
$user = fgets($handle);
fclose($handle);
$handle1 = fopen("password.txt", "r");
$pass = fgets($handle1);
fclose($handle1);
if($username == $user && $password==$pass)
{
echo "logged in!";
}
 
?>
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Login Form ---- Help Me

Post by Benjamin »

I typed this up for you just to get you started. It's just a barebones stripped down basic example and isn't very secure.

Code: Select all

 
# start a session
session_start();
 
# create an array of users
$valid_users = array('bob'    => 'password',
                     'frank'  => 'password',
                     'tina'   => 'password');
 
# check login
//if (empty($_SESSION['authorized']) || $_SESSION['authorized'] !== true)
//{
//    # redirect or exit
//    exit();
//}
 
# wrapper for post vars saves typing 
function post($x)
{
    return emtpy($_POST[$x]) ? null : trim($_POST[$x]);
}
 
if (post('doLogin'))
{
    $user = post('userName');
    if (empty($valid_users[$user]))
    {
        # user doesn't exist
    }
 
    if (post('user_password') != $valid_users[$user])
    {
        # password was wrong
    }
 
    # log em in
    $_SESSION['authorized'] = true;
}
 
easyredboy
Forum Newbie
Posts: 9
Joined: Tue Feb 26, 2008 12:18 am

Re: Login Form ---- Help Me

Post by easyredboy »

Thanx for ur help!

I need one frm which i can import one frm a file
isnt my code correct?
i never get logged in
whats the problem
staar2
Forum Commoner
Posts: 83
Joined: Fri Apr 06, 2007 2:57 am

Re: Login Form ---- Help Me

Post by staar2 »

I see you use text files but my suggestion is to use mysql. Database would more secure and you have less change to mess it up. But if you keep using text files then at least encrypt the password data. :|
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Login Form ---- Help Me

Post by Christopher »

easyredboy wrote:Thanx for ur help!

I need one frm which i can import one frm a file
isnt my code correct?
i never get logged in
whats the problem
Your code is correct ... but a little crazy. It appears that you have one file containing only a username and another file containing only a password. Typically, if you wanted to use a text file, you would have a delimited file like this:

Code: Select all

username    password
foo bar
You can use file() to read that in. You also might want to look into Ninja's CSV class library.
(#10850)
easyredboy
Forum Newbie
Posts: 9
Joined: Tue Feb 26, 2008 12:18 am

Re: Login Form ---- Help Me

Post by easyredboy »

plz can u gimme the code for reading the file which contains username n password
Post Reply