Left Quote    I have not failed. I've just found 10,000 ways that won't work.
- Thomas Alva Edison    
Right Quote
[login] | [Register]

Complete Members System

by: bs0d
Page: 4 of 9
(View All)


Now that we've got an idea of what we need, lets put words to code. First thing's first, we need to connect to the database, because we will be adding a user to the member table. Instead of rewriting the same code over and over for each script to connect, I just put that code in a file, and require it in each script I need to use it, like this:

*Note: If you do not know what needs to be included in this file to make a proper connection to the database, then view this code sample: Database Connection

We're going to be using sessions for the username, login status, etc. We will get to this later, but in our page_header code, sessions have already been started by executing the session_start(); function. In our login script, we'll the create session variables and assign values to them. For login status, we'll apply that to: $_SESSION['logged_in']. The value will be zero if not logged in by default, and one if logged in. Lets check if the visitor is logged in, if they are - then they have already registered, and do not need to be able to visit the register page again. With that being said, we can just redirect them to the home page. Observe code below:

Notice the open } else { at the end. This is because, if the user is not logged in, we're going to carry on with the script. The first thing to assume is that the submit button has been pressed. Basically, going from the end to the start, because the very end of the script will be to display the form. So, lets go though some more code.


This says, if submit button was pressed to execute all code below. Then we check if any value is in username field, if not - kill script and alert the error.

Next thing I chose to do was to declare unwanted characters, and scan the username to see if the potential member chose any of these for their desired username. Below is the code:

$junk is an array of desired invalid characters. In $len, I check the length of the entered username. Then, I basically strip out the invalid characters from the entered username. And finally, I check if the length of $len (starting length) is not equal to the new length (stripping characters out if they exist). If they're not equal, characters were stripped, and I kill the script, and inform the visitor of the error.

1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |  9  |  
Next »


  Subject: "Where to put it?" Date: Feb 29 2008 at 7:49 pm    
Where to put this script:

if($_SESSION[' logged_in'] == 1)....... ect..

Do I put it on header.php? or body.php?
  Subject: "Wherever you want" Date: Mar 01 2008 at 10:47 pm    

You can put that wherever you want to determine if someone is logged in, whatever fits your design. If you do it on the body, make sure your header code defines the logged in status by setting a value to the variable.
  Subject: "dont know" Date: Mar 03 2008 at 4:35 pm    
Hello.. I dont know where all this code's go .. can you tell me where do i need to put the codes like the database conection what i need to name that file and the other code's that you are posting where they go?? please help me
  Subject: "Where does the code go" Date: May 29 2008 at 12:59 am    
Is this the script for checking the register page.

  Subject: "An Error - PHP5 can give trouble so..." Date: Dec 30 2008 at 4:38 pm    

//array of invalid scharacters
$junk = array('.' , ',' , '/' , '\' , '`' , ';' , '[' , ']' , '-' , '*', '&', '^', '%', '$', '#', '@', '!', '~', '+', '(', ')' , '|', '{', '}', '<', '>', '?', ':', '"', '=');

Parse error: syntax error, unexpected '`', expecting ')' in C:\Inetpub\vh osts\mylifeisu\htt pdocs\signup.p hp on line 36

I got this error and I am not sure if it is because of PHP5.
You Must be logged in or a member to comment.

Tutorial Stats

Tutorial Stats

41 Total Comments
4.8 Rating of 5 (5 Votes)


Tutorial Options

· Login to Rate This Article
· Login to Post a Comment
· Read more by this author
Digg This Article! Bookmark This Article Reddit: Bookmark This Article BlinkList: Blink This Article! YahooMyWeb BlogMarks: Add This Mark! Furl: Save This Article Spurl: Mark This Article



· Simple PHP Tutorial
· One File Website
· Pagination with PHP
· Building a Comments Script
· Variable Scope

"" Copyright © 2002-2020; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank