Jump to content

how to make login form


ajax11124

Recommended Posts

I'm new to web building stuff, but interested in learning. i have taught myself a lot of basic HTML but i can't figure out how to make the log in work on websites. How would i go around making a way to log in to my website. And when logged in correctly go to the members area of my website? I know it has somthing to do with Mysql and php but i was hoping for a detailed description on how to do this.

Link to comment
https://forums.phpfreaks.com/topic/118999-how-to-make-login-form/
Share on other sites

Use the site search button, this is a very common thing.

In addition, google would have given you a very wide variety of tutorials had you looked.

 

http://www.google.com/search?q=php+mysql+login+tutorial&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a

First you need a database with a Table of users(or just one users, if needed). The table needs a user_id, user_login, and user_password column(among others, depending what you want).

 

So then you make a form(between <form> tags) that has an input field for the username and password, and a submit button(which goes to a processing page).

 

Then in the processing page, you need to do session_start(); then you do a query to the database to check for the username/password combination that is given. If there is no match, you redirect back to the login page and give an error message. If there is one found, then you redirect to home or wherever you want the user to be directed to.

 

Before redirecting, you also need to setup some session variables to indicate that the user is logged in. I always have a $_SESSION['logged_in'] variable which I set to the value 1, and I make a function logged_in() which check that the $_SESSION['logged_in'] variable is set to 1, and if so then return true. So then, every page that you someone must be logged in to go to, you start the page with "if(!logged_in()) header("Location: login.php"); else // user is logged in so do whatever you need.

 

The thing you have to remember is have session_start(); on every single page that the user will be navigating to. If you forget to, then once the user goes to the page, all session info and variables will be lost and then if the user tries to go somewhere that he needs to be logged in with, it won't allow him.

 

I'm not gonna type all the code out for you(wayyy too much stuff to setup), but now that I've typed it, perhaps others can modify my instructions for better techniques than I said. But it's up to you to type out the code(unless you wanna pay someone to do it, but then what's the point?)

i know your pain. i just figured this out like a couple weeks ago. So first off you must have apache, mysql, and php installed. i prefer xamp.

 

this would take me forever to explain it step by step. i started by googling it and then worked my way from the scripts they provided. BEFORE YOU START TRYING TO PROGRAM IN PHP AND MYSQL you really should know some php. Google php tutorials.

i know your pain. i just figured this out like a couple weeks ago. So first off you must have apache, mysql, and php installed. i prefer xamp.

 

this would take me forever to explain it step by step. i started by googling it and then worked my way from the scripts they provided. BEFORE YOU START TRYING TO PROGRAM IN PHP AND MYSQL you really should know some php. Google php tutorials.

 

 

By talking about apache and whatnot, I realize the extent of vagueness of the original post. Can you tell us if you have a hosting account? and if you do, is it shared, vps, or dedicated? If not, then I suggest looking up some books for php beginners.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.