By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,723 Members | 1,876 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,723 IT Pros & Developers. It's quick & easy.

Login Form

werks
100+
P: 220
hi guy'z Im new in PHP could someone tell me how to create a Login form using PHP?

--
Kenneth
"Better Than Yesterday"
Feb 13 '08 #1
Share this Question
Share on Google+
8 Replies


Markus
Expert 5K+
P: 6,050
hi guy'z Im new in PHP could someone tell me how to create a Login form using PHP?

--
Kenneth
"Better Than Yesterday"
google is your friend ;)
Feb 13 '08 #2

werks
100+
P: 220
Thanks for your advice..

--
Kenneth
"Better Than Yesterday"
Feb 13 '08 #3

harshmaul
Expert 100+
P: 490
Hi werks, you can check this link out...

Creating a PHP CMS for administration
Feb 13 '08 #4

ronverdonk
Expert 2.5K+
P: 4,258
For the last time then, here we go again, a simple form
[php]<?php
session_start();
// -------------------------------
// check if form is submitted
// -------------------------------
$error = false;
if (isset($_POST['_submit']) ) {
if (isset($_POST['userid']) AND isset($_POST['password'])) {
$uid = strip_tags($_POST['uid']);
$psw = strip_tags($_POST['psw']);
// ------------------------------------------------
// Check passed username and password in database
// ------------------------------------------------
// ......
// ..... connect to data base
// ......
// check existence of uid and psw in table
$res = mysql_query("SELECT * FROM authorized_users WHERE userid='$uid' AND passwd=sha1('$psw')")
or die ("SELECT error: " . mysql_error());
if (mysql_num_rows($res) != 1) {
$error = true;
}
else {
// ------------------------------------------------
// userid and psw valid, store userid in session
// ------------------------------------------------
$_SESSION['username'] = strip_tags($_POST['username']);
// ...........
// ===> continue processing valid user
// ===> ...........
}
}
else {
// ------------------------------------------------
// no userid and/or password specified, error
// ------------------------------------------------
$error = true;
}
}
// ------------------------------------------------------
// Display the login form (again)
// ------------------------------------------------------
print "<form name='authForm' method='POST' action='".$_SERVER['PHP_SELF']."'>";
if ($error == true) {
print "<p style='font-weight:bold;color:red'>You have entered an invalid userid and/or password - try again</p>";
}
print "Username&nbsp;<input type='text' name='uid' value='$uid'> <br />";
print "Password&nbsp;<input type='password' name='psw' value='$psw'> <br />";
print '<input type="submit" name="login" value="Login" />';
print '<input type="hidden" name="_submit" value="1"/>';
print '</form>';
?>[/php]
Ronald
Feb 13 '08 #5

werks
100+
P: 220
Hi werks, you can check this link out...

Creating a PHP CMS for administration

Thanks for the link..

--
Kenneth
"Better Than Yesterday"
Feb 15 '08 #6

werks
100+
P: 220
Thank you ronverdonk no hard feelings..

--
Kenneth
"Better Than Yesterday"
Feb 15 '08 #7

ronverdonk
Expert 2.5K+
P: 4,258
See you again.

Ronald
Feb 15 '08 #8

harshmaul
Expert 100+
P: 490
No problem, I'm here to help :)
Feb 15 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.