Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

please help how to make a login form

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

please help how to make a login form

Postby indraisman » Thu Dec 06, 2012 7:29 am

by the way, this is my interface login form, i'm still dont get it how to link with php and phpmyadmin.
can you guys help me?

this is my code interface.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
#apDiv1 {
position: absolute;
left: 320px;
top: 56px;
width: 736px;
height: 480px;
z-index: 1;
background-color: #FFFFFF;
}
</style>
</head>

<body>




<div id="apDiv1">
<p>&nbsp;</p>
<table width="416" height="301" border="1" align="center" >
<tr>
<th scope="col"><p>&nbsp;</p>
<h2 align="center">Sistem Pengurusan Perpustakaan <br />
SMK Pandan Jaya</h2>
<p><img src="xbanner-smkpj20121.png.pagespeed.jpg" width="372" height="105" /></p>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#666699">
<tr>
<form action="login.php" method="post" name="form1" id="form1">
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666699">
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="username" /></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="password" id="password" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Login" />
<input type="reset" name="Submit2" value="Reset" /></td>
</tr>
</table></td>
</form>
</tr>
</table>
<p>&nbsp;</p></th>
</tr>
<tr>
<th scope="col"><form id="form2" name="form2" method="post" action="">
Forgot Password?
<input type="submit" name="Change" id="Change" value="Submit" />
</form></th>
</tr>
</table>
<p>&nbsp;</p>
</div>
</body>
</html>
indraisman
New php-forum User
New php-forum User
 
Posts: 1
Joined: Thu Dec 06, 2012 7:24 am

Re: please help how to make a login form

Postby Barrikor » Thu Dec 06, 2012 4:03 pm

Needed to indent to read...

Your HTML code:
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Untitled Document</title>
        <style type="text/css">
            #apDiv1
                {
                position: absolute;
                left: 320px;
                top: 56px;
                width: 736px;
                height: 480px;
                z-index: 1;
                background-color: #FFFFFF;
                }
        </style>
    </head>
    <body>
        <div id="apDiv1">
        
            <p>&nbsp;</p>
            
            <table width="416" height="301" border="1" align="center" >
                <tr>
                    <th scope="col">
                        
                        <p>&nbsp;</p>
                        
                        <h2 align="center">
                            Sistem Pengurusan Perpustakaan <br/>
                            SMK Pandan Jaya
                        </h2>
                        <p>
                            <img src="xbanner-smkpj20121.png.pagespeed.jpg" width="372" height="105" />
                        </p>
                        
                        <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#666699">
                            <tr>
                                <form action="login.php" method="post" name="form1" id="form1">
                                    <td>
                                        <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666699">
                                            <tr>
                                                <td colspan="3">&nbsp;</td>
                                            </tr>
                                            <tr>
                                                <td width="78">Username</td>
                                                <td width="6">:</td>
                                                <td width="294"><input name="myusername" type="text" id="username" /></td>
                                            </tr>
                                            <tr>
                                                <td>Password</td>
                                                <td>:</td>
                                                <td><input name="mypassword" type="password" id="password" /></td>
                                            </tr>
                                            <tr>
                                                <td>&nbsp;</td>
                                                <td>&nbsp;</td>
                                                <td>
                                                    <input type="submit" name="Submit" value="Login" />
                                                    <input type="reset" name="Submit2" value="Reset" />
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </form>
                            </tr>
                        </table>
                        
                        <p>&nbsp;</p>
                        
                    </th>
                </tr>
                <tr>
                    <th scope="col">
                        <form id="form2" name="form2" method="post" action="">
                            Forgot Password?
                            <input type="submit" name="Change" id="Change" value="Submit" />
                        </form>
                    </th>
                </tr>
            </table>
            
            <p>&nbsp;</p>
            
        </div>
    </body>
</html>
 



Your html looks fine.

<form action="login.php" method="post" name="form1" id="form1">

When your form is submitted, it requests "login.php" and sends the form data to there by using the POST method. The POST data is stored by name

<input name="myusername" type="text" id="username" />
<input 
name="mypassword" type="password" id="password" />

So your PHP script can see the data and take it from POST like this:
Code: Select all

<?php
    
// Get the data from the HTML form
    $username_to_use = htmlentities($_POST['myusername']);
    $password_to_use = htmlentities($_POST['mypassword']);
    
    
// Display the data on the screen
    echo $username_to_use . '---' . $password_to_use;
?>


That's how you "link" your form to PHP,

There's a lot more to it than that though since this is where you've got to watch out for security holes that hackers will try to use to attack your website and screw over your users. Any GET or POST data, any form element is a window that people will try to break into your website through. I used the htmlentities() function above but that's just one defense.


As for linking to MySQL, it's kinda a whole other topic...
Last edited by Barrikor on Fri Dec 07, 2012 9:18 am, edited 3 times in total.
User avatar
Barrikor
New php-forum User
New php-forum User
 
Posts: 16
Joined: Sun Dec 12, 2010 3:14 pm

Re: please help how to make a login form

Postby Barrikor » Thu Dec 06, 2012 4:37 pm

For linking it to MySQL,

How you go about it depends on your setup, but first you create a new Database, called something like "prefix_yourDb", next you create a login to MySQL that your PHP code can use, like "prefix_dbUser" and "dbUserPassword" and then you need to grant privileges to it, (ex: allow it to delete Tables, modify data, ect.) Then you create a Table in that Database with the fields you want.

For your table you'll need to store user_id, username, email, password_hash


user_id
- Set this field to int and to auto-increment. Having this field lets you can change a user's name without messing everything up. Auto-increment makes the user id go up +1 each time a new Row (new user) is added to this Table. Unlike the other fields, you don't need to set the data for this field, instead you'll find the user_id AFTER the user is created.

username
- This is where the username is stored, set it to varchar(255) and add a Unique constraint to force it to not store the username if the same username already exists.

email
- While not necessary there's 3 big reasons everyone stores it: it's useful for a password reset function, users could use that to login instead of / or alongside using the username, it makes it hard work for people who decide to create a hundred fake accounts on your site, since they'll need a different email for each. Set it to varchar(255) and add a Unique constraint to it.

password_hash
- Use this field to store a 1-way encryption of the password. 1-Way encryption because you NEVER store the actual password or even store a version of the password that can be decrypted. Instead you store the encryption of the password. When someone logs in you'll take the password that they type in, and encrypt that password the same way, then you see if the encryption of that password matches the one in the database for that user. Set it to varchar(255) or maybe 64 or 32 since depending on what encryption functions you use, it might have the same string length for every user.


Then to talk to MySQL you've got to use either PHP's "mysql" lib or PHP's "mysqli" lib or "PDO"...

PHP's mysql
- Old lib, lots of people know how to use it, lots of examples to use, unable to use prepared statements

mysqli
- New lib, more complicated until you understand the idea behind it, feels like it has important parts missing, but can do things that the old mysql lib can't do like prepared statements, not much documentation or examples (But this is the one I use)

PDO - PHP Data Objects
- (I've never used it so take this with a grain of salt) PDO is a bit simpler to use, and can be used for other databases not just MySQL, not as many examples on the internet as the mysql lib, and can't do quite all the things that mysqli can do.
User avatar
Barrikor
New php-forum User
New php-forum User
 
Posts: 16
Joined: Sun Dec 12, 2010 3:14 pm

Re: please help how to make a login form

Postby webinfopedia » Fri Dec 14, 2012 2:55 am

Hi
Take a look at this article. This will help you

http://www.webinfopedia.com/php-secure-login-script.html

Thank you
webinfopedia
http://www.webinfopedia.com
User avatar
webinfopedia
New php-forum User
New php-forum User
 
Posts: 84
Joined: Sat May 21, 2011 10:26 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot], Google Feedfetcher and 6 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.