You are invited to Log in or Register a free Frihost Account!

How to make a log in log out system for a website??

Hey guys please can some one tell me how to make a system where you have to register an account to access my site. eg like on this forum
Okay. I only know PHP, so I'm gonna approach the problem from that angle. But what I'm gonna give you here is an outline. It just wouldn't be any fun if I gave you all the code, ya know?

The first thing you're gonna need is some sort of database. This will be to store authorized username/password combinations. Databases are actually fairly easy to implement, and I'm sure you can Google up a few examples. You're not going to need anything really fancy if you're simply concerned with limiting viewing access, but if you want to store other information about people, your database might need to be a little more complicated.

Once you have a place to store authorized usernames/passwords, the next thing you're going to have to decide is whether to use (providing you're doing this in PHP) sessions or cookies. Both of these are ways to store a variable for the entire time a person is on your site (as opposed to just on one page). The difference is that cookies are stored as small files on the user's computer, and session information is stored on the server. I think either one will work for you, but sessions might be somewhat more secure.

Now, this is what will basically happen on your site. First off, when people want to log on, you will provide them with a small form that requests their screename and password. Once they submit the form, you're site will have to check to see if they're authorized. If they aren't, you will need to ask them nicely to try again. If they are authorized, however, the simplest thing would be at that point to set a session or cookie variable that says they are authorized.

Now, once the variable is set, direct them to the restricted portion of your page. At the top of every page, however, in the code, you will need to check if they are authorized. If their cookie says that they are indeed authorized, then it should allow them to see the page. If they are not authorized, then the page should redirect them to the login page. This is to prevent somebody from just linking to one of your pages without logging in.

Both sessions and cookies will automatically delete themselves once a user leaves a website, absolutely negating the need for a logout system. But if you do want to implement one, it is a simple matter of linking to a page that sets the cookie to an empty value.

That's the basic outline of what you need to do. It should actually be quite simple to accomplish in PHP, but I'll leave the fun part to you.
Probably you will be interested in the PEAR::Auth package.
Related topics
How To : Secure Your PHP Website
751 Useful Windows XP Files
Making Your Website Look Professional
ASP content management system
Site Members' System
Login System help
SQL error
Developing a Login System with PHP and MySQL
Login System Tutorial Part 1 Creating Registration
Log in system
Has your website ever been attacked? What did you learn
Finding full website log files
Secure log in System
could i Upgrade my free account upto 50GB bandwidth
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

© 2005-2011 Frihost, forums powered by phpBB.