Login, Register script

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
tecmeister
Forum Newbie
Posts: 4
Joined: Tue Jan 22, 2008 4:22 pm

Login, Register script

Post by tecmeister »

Hi everyone,

Im new to php.
I would like to know how to create a login register page. Like the register page on this website.
I have look at some toturials, but they either have login or register.
Would some please be able to show me a tutorial or give me advice on how to do it.

Thankyou very much for the help that you be able to give me.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Login, Register script

Post by Christopher »

There are two main parts to this 1) authenticating the user via a login form and 2) having access controls on pages to prevent users without permission to view the page. Which would you like to implement first?
(#10850)
User avatar
Josh1billion
Forum Contributor
Posts: 316
Joined: Tue Sep 11, 2007 3:25 pm

Re: Login, Register script

Post by Josh1billion »

Register page:
1. Make a page "register.php"
2. It should contain an HTML form which submits to register.php (itself). Only print the form if the form has not been submitted.
2. If the form has been submitted, insert the username/password/etc. as a new row in your "users" table.

Login page:
1. Make a page "login.php"
2. It should contain an HTML form (login form) which submits to login.php (itself). Only print if the form has not been submitted.
3. If the form has been submitted, check the username/password and if they're correct, store a cookie (or if you prefer, start a session-- cookies are potentially more simple).
User avatar
hannnndy
Forum Contributor
Posts: 131
Joined: Sat Jan 12, 2008 2:09 am
Location: Iran>Tehran
Contact:

Re: Login, Register script

Post by hannnndy »

you can use this as a guide i think it will help you a lot

Code: Select all

 
<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
    header('WWW-Authenticate: Basic realm="My Realm"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Text to send if user hits Cancel button';
    exit;
} else {
    echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
    echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
}
?>
 
it would help you if you dont want any html form

google is your friend
look at this url too http://us3.php.net/features.http-auth
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Login, Register script

Post by RobertGonzalez »

Moved to PHP - Code since this started taking on coding and programming related content.
Post Reply