Forum Moderators: coopster

Message Too Old, No Replies

Simple Login Page

         

ganie17

4:11 am on Nov 17, 2004 (gmt 0)

10+ Year Member



Good day to all...
Can any one help me in my project...
I'm totally a newbie here.
I would like to ask on how to create a PHP script with my login page.

These are my details:
txtusername -> for username
txtpassword -> for password

$host = "localhost"
$database = "crismon"

my database type is MYSQL.

I hope someone can help me on this thanks!

mincklerstraat

8:17 am on Nov 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ganie, you'll probably want to find a tutorial on 'authentication' and php - that's the geek term for 'log-in and all that security stuff'. You can google authentication tutorial php and see what you find, there will be lots out there.

If you're happy with simplicity, you can just do:


session_start();
if(!empty($_SESSION['logged_in'])){
echo 'you\'re logged in!';
} elseif(!empty($_POST['username']) &&!empty($_POST['password']) && $_POST['username'] == 'txtusername' && $_POST['password'] == 'txtpassword'){
$_SESSION['logged_in'] = 1;
echo 'thanks for logging in!';
} else {
echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">';
echo 'username: <input type="text" name="username" /><br />
password: <input type="password" type="text" name="password" /><br />
<input type="submit" value="log in" />';
}

and on each page inside the part that's protected by the login, at the top:

session_start();
if(empty($_SESSION['logged_in'])) die('please log in first at <a href="url">this url</a>');

coopster

11:30 am on Nov 17, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, ganie17.

The PHP Session Handling Functions [php.net] page will be of great help as well. You'll also find a few tutorial links in the User Contributed Notes.

mipapage

11:38 am on Nov 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This post [webmasterworld.com] (msg #3) by jatar k provided the foundation to what has become the login script I use on all of our sites now. It isn't perfected yet, but it does the job ;-]