SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help Learning How to Write a Login Form

    I need a login form for a website I'm designing. I considered taking the easy way out and using a pre-made script, but after reading and thinking I figure while it may take lots of time NOW to learn how to do it, in the long run it's worth it.

    A post in the thread "what login script do you use?" somewhat outlined all the components needed to make up the entire thing (I'd link to it, but unfortunately, am not allowed to yet)

    I'm hoping someone can A) Give me a general idea of the entire process. B) Point me in the direction of where I can find the most comprehensive help. I've looked around online (for the past 4 days) and it's really overwhelming. Seems like most demos or tutorials either start halfway into it, or end before it's completely done, up and running.


    Also, would it be easier if I found a pre-made script to learn from and start writing my own based off that? Could someone provide one? I don't need a registration form, because the client will be providing login names and passwords for HIS clients.

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Learning from pre-made scripts has its benefits and its downfalls - most notably that you are going to pick up bad habits. Programmers tend to go through 'phases' so chances are an article could simply reflect what the author liked at the time; This phase would usually pass and you would be using unrecommended techniques.

    How much do you know in terms of PHP?

    I'd say you need to know the following in PHP at the very least. If you don't know one (or more) of them, learn it/them from the [url=http://www.php.net]PHP manual[/php]:


    • Forms
      • How to collect data sent to the page with a form
      • Why and how to escape potentially dangerous (i.e. ALL) data input from forms. If you use mysql, this would be with mysql_real_escape_string
      • Why and how to VALIDATE input data

    • MySQL
      • Selecting data from a database.
      • Inserting data into a database.
      • Updating data in a database

    • Sessions
      • Session theory - what they are, how to load session capability (session_start())
      • How to create and edit session values
      • How to retrieve session values and display them in a page.




    Once you know all that, I'll help you out in more detail.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok. I read 90% of the PHP Manual. Still kinda confused...but I'm starting to grasp writing the code at least.

    I've looked at some login scripts I found and compared them to scripts in the manual and and see things that are needed to run the script and things that are just for formatting, etc.

    I think I get how to create a database...name it then click "create database" Then I add users by entering their username and password into the new users section. Is that right? If I create a database called "login" I enter usernames and passwords and that's what they use to login to the site??

    Assuming that's all correct the only part I'm missing: How do I "connect" my database to the php script?? I can't find any good tutorial that shows how to set up a login using PHP AND MySQL, they all just say "set up a database."

    I've done a lot of complicated reading today, so if you could use really small words that would be great haha

  4. #4
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok. I read 90% of the PHP Manual.
    You read 90% of the entire PHP manual? Wow!


    It would be best to read up on all the points arkinstall mentioned. Try the links below.

    PHP MySQL Introduction
    Use the Next button to view the related topics on connecting, inserting, selecting, etc.

    PHP MySQL Manual

    PHP Forms and User Input

    Dealing with Forms

    PHP Sessions

    Session Handling

    Once you've done reading, create your log in script and try it. If you have a error or it's not working properly, see if you can easily find what the problem might be. If not, post the code here for help.

  5. #5
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I feel so dumb that I can't figure this out.

    I followed this tutorial http://adriaanvm.com/archives/howto-...in-form-in-php

    So now I have a bunch of codes saved as files on my computer...and that's where I get stuck. What do I DO with all this coding? Paste it into my source code? Or upload the files to my public_html folder?

  6. #6
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you understand the tutorial? Do you understand the HTML form and how it works with PHP? If not, try reading through it again after taking a relaxing break. Sometimes a fresh set of eyes can help you to understand something that is new and that seems daunting.

    The tutorial fails to include the mention of using mysql_real_escape_string and validation of input data that is used with the database queries. This is very important to prevent SQL injection. Once you have a good grasp of this you can look at the advanced method of doing so using PDO.

    So now I have a bunch of codes saved as files on my computer...and that's where I get stuck. What do I DO with all this coding? Paste it into my source code? Or upload the files to my public_html folder?
    To use the form and PHP you would need to upload the files to your web site hosting server where the database and its tables should be as well.

  7. #7
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Don't use straight tutorials - that really won't help you.

    You should use your own code. Now, have you learned the list of things I gave you above or not? If you want to learn how to program these things, downloading someone else's code - which would be meant to accomplish something with maybe different goals - really won't help you.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •