Search TekSocial
Stay Connected

Enter your email address:

(We respect your privacy!)

Or subscribe with your favorite RSS Reader

  

« Button Press Pop Up Alert | Main | Young Photographer »
5:36AM

A Basic Login PHP Script

Hi,

PHP can be difficult sometimes, to me when I tried to learn it on my own without any help whatsoever became a real problem. So when I tried to develop my first PHP Login script, it didn’t really work. Finally I found help for a basic login script through a YouTube video. Now the reason I told you this story is to tell you that in this post, this will not happen to you. Instead of giving you code to jot down, I will give you all of the things a login script needs and then you code your way through.  The reason, I will not give away the source code to those who are lazy and just copy and paste. Don’t try to prove me wrong, because I have seen them.

Input – before any of the PHP code begins, you need some way for the user to enter his username and password. This is where your basic HTML comes in. Use the <input> tag to give the user some text area to add their information.

Preliminary Actions – Now before we start, be sure to have your Apache and MYSQL servers up and running because you will need both. And, have all of the files that we are going to be using today are in the directory that have both of the servers running.

SQL – Though this language has been around for a long time, it will be needed to get to hold the registered usernames and passwords.

User Submission – This is where the real code begins. First you will need to take the information that the user inputted in the text field and match it with the database of username’s and passwords. The way you do that is to make sure that the input fields that we added using HTML is wrapped inside a form tag. Also, have your method of the form tag is set to post. Then, take use the PHP function $_POST to gather the user.

Match Towards Database – Now you will have to compare the user submitted data to the database that contains the registered users. This requires a PHP/SQL scripting. Specifically, the mysql_query function. This is used within PHP but does the work of a regular SQL script. You then want to select all of the data within the database where the username equals the inputted username and the password equals the inputted password. This can easily be done with SQL.

Some Ending IF Statements – Now that you have all the hard stuff down, add some extra if statements that will say if it is incorrect, print out saying “Invalid Username and Password”. Or if some fields have not been filled out, state it out. This can all be done with the IF Statements.

And what do you know you have finished! I hope everyone enjoyed it and to give you a challenge, try and create a register page? Trust me, it is much simpler than the login page.

Cheers,

*Note: The way I have developed a basic Login script is by using these steps, if these are not the steps you use then do not blame me.

 

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>