Page 1 of 1

How to create a simple login form for a web, with no regis..

Posted: Sat Jul 23, 2011 9:38 am
by webuxer
Hi
Im new to php, im in the process of learning. I want to put a login form on my html site to protect a page. The login should only need a username and password. I would like to store the username and the password in the mysql database myself, thats why i don't need a registration feature, i will supply the username and password myself, and tell my customers their login info. For example all my customers have a four number customer code, i will use their customer code and just make up a password for all the customers. Can someone help me create this?
My site is currently hosted by godaddy, so i can use php and mysql.

Thanks In Advance.

Re: How to create a simple login form for a web, with no reg

Posted: Sat Jul 23, 2011 10:45 am
by Neilos
All would depend on where you want the login form to appear, do you want all pages to display the login form by default unless the user is logged in?

If so you will probably want to utilise sessions where you firstly check a session variable to see if they are logged in, if they are you load the page if not you load a login form that posts data to the same page you are on.

I would have a login form on a separate document which you include at the top of every page, the form may look like..

Code: Select all

echo '<form action="' . $currentPage . '" method="post">\n';
// rest of form here
echo '</form>';
$currentPage would be dynamically fetched each time.

On reloading the page you'd check the POST variable in the database and if correct you'd say something like $_SESSION['logged'] = 1; $_SESSION['username'] = $_POST['username'];

Re: How to create a simple login form for a web, with no reg

Posted: Sat Jul 23, 2011 10:53 am
by webuxer
HI Thanks
No the login form will be in a single page, no need to track if the user is logged in or not.

Re: How to create a simple login form for a web, with no reg

Posted: Sat Jul 23, 2011 11:29 am
by Neilos
Even if it is just on a single page the process is much the same. The logic goes like;

[syntax]
User Arives on page
|
Check Post variables against db (login if they are correct)
|
Are they logged in? --- Yes --- Then Display Page
|
No
|
Then display Login form (which posts back to this page)
[/syntax]