User Membership With PHP

User Membership With PHP

Tutorial Details
  • Technology: PHP, CSS
  • Difficulty: Intermediate
  • Completion Time: 1-2 hours

A tutorial for the very beginners! No matter where you go on the internet, there’s a staple that you find almost everywhere – user registration. Whether you need your users to register for security or just for an added feature, there is no reason not to do it with this simple tutorial. In this tutorial we will go over the basics of user management, ending up with a simple Member Area that you can implement on your own website.


Introduction

In this tutorial we are going to go through each step of making a user management system, along with an inter-user private messaging system. We are going to do this using PHP, with a MySQL database for storing all of the user information. This tutorial is aimed at absolute beginners to PHP, so no prior knowledge at all is required – in fact, you may get a little bored if you are an experienced PHP user!

This tutorial is intended as a basic introduction to Sessions, and to using Databases in PHP. Although the end result of this tutorial may not immediately seem useful to you, the skills that you gain from this tutorial will allow you to go on to produce a membership system of your own; suiting your own needs.

Before you begin this tutorial, make sure you have on hand the following information:

  • Database Hostname – this is the server that your database is hosted on, in most situations this will simply be ‘localhost’.
  • Database Name, Database Username, Database Password – before starting this tutorial you should create a MySQL database if you have the ability, or have on hand the information for connecting to an existing database. This information is needed throughout the tutorial.

If you don’t have this information then your hosting provider should be able to provide this to you.

Now that we’ve got the formalitiies out of the way, let’s get started on the tutorial!


Step 1 - Initial Configuration

Setting up the database

As stated in the Introduction, you need a database to continue past this point in the tutorial. To begin with we are going to make a table in this database to store our user information.

The table that we need will store our user information; for our purposes we will use a simple table, but it would be easy to store more information in extra columns if that is what you need. In our system we need the following four columns:

  • UserID (Primary Key)
  • Username
  • Password
  • EmailAddress

In database terms, a Primary Key is the field which uniquely identifies the row. In this case, UserID will be our Primary Key. As we want this to increment each time a user registers, we will use the special MySQL option – auto_increment.

The SQL query to create our table is included below, and will usually be run in the ‘SQL’ tab of phpMyAdmin.

CREATE TABLE `users` (
`UserID` INT(25) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`Username` VARCHAR(65) NOT NULL ,
`Password` VARCHAR(32) NOT NULL ,
`EmailAddress` VARCHAR(255) NOT NULL
);

Creating a base file

In order to simplify the creation of our project, we are going to make a base file that we can include in each of the files we create. This file will contain the database connection information, along with certain configuration variables that will help us out along the way.

Start by creating a new file: base.php, and enter in it the following code:

<?php
session_start();

$dbhost = "localhost"; // this will ususally be 'localhost', but can sometimes differ
$dbname = "database"; // the name of the database that you are going to use for this project
$dbuser = "username"; // the username that you created, or were given, to access your database
$dbpass = "password"; // the password that you created, or were given, to access your database

mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error());
mysql_select_db($dbname) or die("MySQL Error: " . mysql_error());
?>

Let’s take a look at a few of those lines shall we? There’s a few functions here that we’ve used and not yet explained, so let’s have a look through them quickly and make sense of them — if you already understand the basics of PHP, you may want to skip past this explanation.

session_start();

This function starts a session for the new user, and later on in this tutorial we will store information in this session to allow us to recognise users who have already logged in. If a session has already been created, this function will recognise that and carry that session over to the next page.

mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error());
mysql_select_db($dbname) or die("MySQL Error: " . mysql_error());

Each of these functions performs a separate, but linked task. The mysql_connect function connects our script to the database server using the information we gave it above, and the mysql_select_db function then chooses which database to use with the script. If either of the functions fails to complete, the die function will automatically step in and stop the script from processing – leaving any users with the message that there was a MySQL Error.


Step 2 - Back to the Frontend

What do we need to do first?

The most important item on our page is the first line of PHP; this line will include the file that we created above (base.php), and will essentially allow us to access anything from that file in our current file. We will do this with the following line of of PHP code. Create a file named index.php, and place this code at the top.

<?php include "base.php"; ?>

Begin the HTML page

The first thing that we are going to do for our frontend is to create a page where users can enter their details to login, or if they are already logged in a page where they can choose what they then wish to do. In this tutorial I am presuming that users have basic knowledge of how HTML/CSS works, and therefore am not going to explain this code in detail; at the moment these elements will be unstyled, but we will be able to change this later when we create our CSS stylesheet.

Using the file that we have just created (index.php), enter the following HTML code below the line of PHP that we have already created.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<title>User Management System (Tom Cameron for NetTuts)</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>  
<body>  
<div id="main">

What shall we show them?

Before we output the rest of the page we have a few questions to ask ourselves:

  1. Is the user already logged in?
    • Yes – we need to show them a page with options for them to choose.
    • No – we continue onto the next question.
  2. Has the user already submitted their login details?
    • Yes – we need to check their details, and if correct we will log them into the site.
    • No – we continue onto the next question.
  3. If both of the above were answered No, we can now assume that we need to display a login form to the user.

These questions are in fact, the same questions that we are going to implement into our PHP code. We are going to do this in the form of if statements. Without entering anything into any of your new files, lets take a look at the logic that we are going to use first.

<?php
if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username']))
{
	// let the user access the main page
}
elseif(!empty($_POST['username']) && !empty($_POST['password']))
{
	// let the user login
}
else
{
	// display the login form
}
<?>

Looks confusing, doesn’t it? Let’s split it down into smaller sections and go over them one at a time.

if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username']))
{
	// let the user access the main page
}

When a user logs into our website, we are going to store their information in a session – at any point after this we can access that information in a special global PHP array – $_SESSION. We are using the empty function to check if the variable is empty, with the operator ! in front of it. Therefore we are saying:

If the variable $_SESSION['LoggedIn'] is not empty and $_SESSION['Username'] is not empty, execute this piece of code.

The next line works in the same fashion, only this time using the $_POST global array. This array contains any data that was sent from the login form that we will create later in this tutorial. The final line will only execute if neither of the previous statements are met; in this case we will display to the user a login form.

So, now that we understand the logic, let’s get some content in between those sections. In your index.php file, enter the following below what you already have.

<?php
if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username']))
{
	 ?>

	 <h1>Member Area</h1>
     <pThanks for logging in! You are <b><?=$_SESSION['Username']?></b> and your email address is <b><?=$_SESSION['EmailAddress']?></b>.</p>
     
     <?php
}
elseif(!empty($_POST['username']) && !empty($_POST['password']))
{
	$username = mysql_real_escape_string($_POST['username']);
    $password = md5(mysql_real_escape_string($_POST['password']));
    
	$checklogin = mysql_query("SELECT * FROM users WHERE Username = '".$username."' AND Password = '".$password."'");
    
    if(mysql_num_rows($checklogin) == 1)
    {
    	$row = mysql_fetch_array($checklogin);
        $email = $row['EmailAddress'];
        
        $_SESSION['Username'] = $username;
        $_SESSION['EmailAddress'] = $email;
        $_SESSION['LoggedIn'] = 1;
        
    	echo "<h1>Success</h1>";
        echo "<p>We are now redirecting you to the member area.</p>";
        echo "<meta http-equiv='refresh' content='=2;index.php' />";
    }
    else
    {
    	echo "<h1>Error</h1>";
        echo "<p>Sorry, your account could not be found. Please <a href=\"index.php\">click here to try again</a>.</p>";
    }
}
else
{
	?>
    
   <h1>Member Login</h1>
    
   <p>Thanks for visiting! Please either login below, or <a href="register.php">click here to register</a>.</p>
    
	<form method="post" action="index.php" name="loginform" id="loginform">
	<fieldset>
		<label for="username">Username:</label><input type="text" name="username" id="username" /><br />
		<label for="password">Password:</label><input type="password" name="password" id="password" /><br />
		<input type="submit" name="login" id="login" value="Login" />
	</fieldset>
	</form>
    
   <?php
}
?>

</div>
</body>
</html>

Hopefully, the first and last code blocks won’t confuse you too much. What we really need to get stuck into now is what you’ve all come to this tutorial for – the PHP code. We’re now going to through the second section one line at a time, and I’ll explain what each bit of code here is intended for.

	 $username = mysql_real_escape_string($_POST['username']);
    $password = md5(mysql_real_escape_string($_POST['password']));

There are two functions that need explaining for this. Firstly, mysql_real_escape_string – a very useful function to clean database input. It isn’t a failsafe measure, but this will keep out the majority of the malicious hackers out there by stripping unwanted parts of whatever has been put into our login form. Secondly, md5. It would be impossible to go into detail here, but this function simply encrypts whatever is passed to it – in this case the user’s password – to prevent prying eyes from reading it.

	 $checklogin = mysql_query("SELECT * FROM users WHERE Username = '".$username."' AND Password = '".$password."'");
    
    if(mysql_num_rows($checklogin) == 1)
    {
    	 $row = mysql_fetch_array($checklogin);
        $email = $row['EmailAddress'];
        
        $_SESSION['Username'] = $username;
        $_SESSION['EmailAddress'] = $email;
        $_SESSION['LoggedIn'] = 1;

Here we have the core of our login code; firstly, we run a query on our database. In this query we are searching for everything relating to a member, whose username and password match the values of our $username and $password that the user has provided. On the next line we have an if statement, in which we are checking how many results we have received – if there aren’t any results, this section won’t be processed. But if there is a result, we know that the user does exist, and so we are going to log them in.

The next two lines are to obtain the user’s email address. We already have this information from the query that we have already run, so we can easily access this information. First, we get an array of the data that has been retrieved from the database – in this case we are using the PHP function mysql_fetch_array. I have then assigned the value of the EmailAddress field to a variable for us to use later.

Now we set the session. We are storing the user’s username and email address in the session, along with a special value for us to know that they have been logged in using this form. After this is all said and done, they will then be redirect to the Member Area using the META REFRESH in the code.

So, what does our project currently look like to a user?

Great! It’s time to move on now, to making sure that people can actually get into your site.

Let the people signup

It’s all well and good having a login form on your site, but now we need to let user’s be able to use it – we need to make a login form. Make a file called register.php and put the following code into it.

<?php include "base.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  

<title>User Management System (Tom Cameron for NetTuts)</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>  
<body>  
<div id="main">
<?php
if(!empty($_POST['username']) && !empty($_POST['password']))
{
	$username = mysql_real_escape_string($_POST['username']);
    $password = md5(mysql_real_escape_string($_POST['password']));
    $email = mysql_real_escape_string($_POST['email']);
    
	 $checkusername = mysql_query("SELECT * FROM users WHERE Username = '".$username."'");
     
     if(mysql_num_rows($checkusername) == 1)
     {
     	echo "<h1>Error</h1>";
        echo "<p>Sorry, that username is taken. Please go back and try again.</p>";
     }
     else
     {
     	$registerquery = mysql_query("INSERT INTO users (Username, Password, EmailAddress) VALUES('".$username."', '".$password."', '".$email."')");
        if($registerquery)
        {
        	echo "<h1>Success</h1>";
        	echo "<p>Your account was successfully created. Please <a href=\"index.php\">click here to login</a>.</p>";
        }
        else
        {
     		echo "<h1>Error</h1>";
        	echo "<p>Sorry, your registration failed. Please go back and try again.</p>";    
        }    	
     }
}
else
{
	?>
    
   <h1>Register</h1>
    
   <p>Please enter your details below to register.</p>
    
	<form method="post" action="register.php" name="registerform" id="registerform">
	<fieldset>
		<label for="username">Username:</label><input type="text" name="username" id="username" /><br />
		<label for="password">Password:</label><input type="password" name="password" id="password" /><br />
        <label for="email">Email Address:</label><input type="text" name="email" id="email" /><br />
		<input type="submit" name="register" id="register" value="Register" />
	</fieldset>
	</form>
    
    <?php
}
?>

</div>
</body>
</html>

So, there’s not much new PHP that we haven’t yet learnt in that section. Let’s just take a quick look at that SQL query though, and see if we can figure out what it’s doing.

$registerquery = mysql_query("INSERT INTO users (Username, Password, EmailAddress) VALUES('".$username."', '".$password."', '".$email."')");

So, here we are adding the user to our database. This time, instead of retrieving data we’re inserting it; so we’re specifying first what columns we are entering data into (don’t forget, our UserID will go up automatically). In the VALUES() area, we’re telling it what to put in each column; in this case our variables that came from the user’s input. So, let’s give it a try; once you’ve made an account on your brand-new registration form, here’s what you’ll see for the Member’s Area.

Make sure that they can logout

We’re almost at the end of this section, but there’s one more thing we need before we’re done here – a way for user’s to logout of their accounts. This is very easy to do (fortunately for us); create a new filed named logout.php and enter the following into it.

<?php include "base.php; $_SESSION = array(); session_destroy(); ?>
<meta http-equiv="refresh" content="0;index.php">

In this we are first resetting our the global $_SESSION array, and then we are destroying the session entirely.

And that’s the end of that section, and the end of the PHP code. Let’s now move onto our final section.


Step 3 - Get Styled

I’m not going to explain much in this section – if you don’t understand HTML/CSS I would highly reccomend when of the many excellent tutorials on this website to get you started. Create a new file named style.css and enter the following into it; this will style all of the pages that we have created so far.

* {
	margin: 0;
    padding: 0;
}
body {
	font-family: Trebuchet MS;
}
a {
	color: #000;
}
a:hover, a:active, a:visited {
	text-decoration: none;
}
#main {
	width: 780px;
    margin: 0 auto;
	margin-top: 50px;
	padding: 10px;
    border: 1px solid #CCC;
    background-color: #EEE;
}
form fieldset {	border: 0; }
form fieldset p br { clear: left; }
label {
	margin-top: 5px;
    display: block;
    width: 100px;
    padding: 0;
    float: left;
}
input {
	font-family: Trebuchet MS;
    border: 1px solid #CCC;
	margin-bottom: 5px;
    background-color: #FFF;
    padding: 2px;
}
input:hover {
	border: 1px solid #222;
    background-color: #EEE;
}

Now let’s take a look at a few screenshots of what our final project should look like:

The login form.

The member area.

The registration form.

And finally…

And that’s it! You now have a members area that you can use on your site. I can see a lot of people shaking their heads and shouting at their monitors that that is no use to them – you’re right. But what I hope any beginners to PHP have learned is the basics of how to use a database, and how to use sessions to store information. The vital skills to creating any web application.

  • Subscribe to the NETTUTS RSS Feed for more daily web development tuts and articles.


Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://www.c-efx.com Chris

    Hey great tut worked perfect for me. I was just wondering if you could do a follow up tut on expanding this membership.

    E.g. a profile page, or message system or something the members them selves can play about with?

  • Rhett

    I have to add to the chatter: I too loved this beginner tutorial and would love to see a “Step 2″.

  • http://twitter.com/saurabhshah Saurabh Shah

    simple and nice1 … !

  • Adam B.

    Nice Tutorial

  • John

    HI i am getting the following problem:

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

    can anyone solve it plz it’s urgent thks

  • John

    The problem………Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource has been resolved now the problem that i am getting is : Sorry, your account could not be found. Please click here to try again.

    plz help

  • http://www.techcorner.it Giuseppe

    Great tutorial !

    Thanks a lot,

  • marcelo

    Greta tutorial :). Very simple to use

    Thanks

  • Me

    Great tutorial, thanks a lot :)

    I learnt quite a bit from this tutorial. Thanks Tom for replying to the email I sent you, I’ve got it working now :) Also managed to make a user page which displays the specified user’s details.

  • osman Butt

    Really Nice ….. its Aw Som…. …

  • A001

    A great tutorial Tom but I cant seem to get logout.php to work
    I keep getting this error:
    Parse error: syntax error, unexpected T_STRING in C:\Program Files\Apache Group\Apache2\htdocs\logout.php on line 2
    I’ve copied it exactly as it is in the tutorial has anyone else encountered this? and does anyone have the solution please I would appreciate it cheers

  • A001

    Forget my last comment Marcel Doornbos already solved the problem :)
    This keeps displaying across the screen however:
    Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at C:\Program Files\Apache Group\Apache2\htdocs\base.php:3) in C:\Program Files\Apache Group\Apache2\htdocs\base.php on line 4

    and when Im in the member area logout does not appear can anyone help?

  • A001

    Ok I believe I fixed the logout problem you need to add this line of code to index.php at line 8 if you look at the tutorial

    This will create a logout button which will activate logout.php

    Is this an acceptable method????

    If anyone has the solution to my other problem please help

  • A001

    Ignore brackets
    (((((

    )))))

  • phpProgrammer_class

    echo “”;

    that line doesn´t work properly, because there’s an error in the sintax, the error is the double equal and the url parameter is not defined in the script

    the modified version of this line should be like this.

    echo “”;

    and the modified version of the logout script should be like this

    However i prefer to use the header function like this

    header(‘Location: index.php’);

  • Ahmed Mahrous

    Thanks man

  • Karl H

    Were do you get the ['LoggedIn'] from?
    im very very new to this!
    doesnt $_SESSION['Username'] get the Username value from the form input?

    That maybe a stupid question, sorry.

    Very nice tutorial :)

  • http://onlinelife09.wordpress.com heam

    good job m8 !
    is it possible to tell me how can i make a new page ” members.php ” and show all of users in this page ?

  • organicIT

    heam
    hunt around for the other tuts on returning sql queries to html unordered lists.

    minus the tweaks and tunes needed without the source this is an outstanding tut for a php newbie like me.

    thank you!

  • http://www.whybored.com Siddhu Panchal

    It’s best tutorials for beginner,but if you use something more easy for user to update their MySQL dbname , username , host & password by simply getting from them by text input ,So make changes in base.php

    something like this:

    Host Name:
    Database Name:
    Database Username:
    Username Password:

  • http://www.whybored.com Siddhu Panchal

    Oh go on this website!we can’t post php codes over here.

    http://phpuser-user.blogspot.com/

  • http://www.arabaoyunlari60.com Araba Oyunları

    Thank you , very good

  • Pingback: A Better Login System - Nettuts+

  • d00d

    I made a login system for a forum from a tutorial on the net. It turned out to be woefully, disastrously insecure. This one doesn’t seem too secure either, and adding cookies would make it even less secure.

    The only way I’d touch a login system is if I knew it was rock-solid. I haven’t seen any tutorials that are adequate yet.

    • http://www.fabricgames.com Wouter Bulten

      The only rock-solid login system is the system you create yourself. You should combine multiple authentication systems such as normal sessions, cookies and the databse. Also encrypting a password with md5 is very very insecure! Use something like:

      $password = sha1(md5($password . ‘asdf*SD)F7923isdfyuSDi’));

      A second thing: why would you save the username in the session? Usernames can often be changed. It is better to store the ID of the user in the session.

      • Ben D.

        “The only rock-solid login system is the system you create yourself.”

        I would dispute that. There’s probably no such thing as a rock-solid login system, but whatever you do, don’t create one yourself unless there’s absolutely no way to avoid it. You would be much better off re-using a system with some pedigree.

        A cardinal rule of infosec is “don’t reinvent the wheel”. This is always important in programming, but especially so in security, because security errors are often subtle and are best teased out of a system by long exposure to real-world use.

        Plus very few people actually understand encryption and hashing and the other building-blocks of security. I don’t claim to understand these things myself, but I wouldn’t be surprised to learn that your sha1(md5()) technique above actually increases your exposure to a collision attack. Hash functions are tricky animals.

        Also I’m wondering why the crazy string concatenation. Looks like you’re intending to salt your password, but as I understand it, salts are only useful if they’re different for every user, and they don’t gain any strength by being made long and complex. They do become harder to use when they’re long and complex, though. ;-)

  • http://jibjub.com sonicoliver

    nice one! thank-you!!!

  • http://haktstudios.com/ t0ne

    People getting the login error, there are two instances that will result in that error,

    1. your password for that database account is wrong.
    2. you don’t have a password set on that database account.

    case 2 is by far the most common case, so try logging in from a terminal without the password options, and if it lets you in, you need to set a password on your sql. In the other case, verify the password you are using is entered correctly, and verify that it works through terminal access before saying there isn’t a problem with it.

  • http://none kaise

    Anyone know where I can get a complete login system tutorial withsource code.

    Something that implements the following

    MySQL Table Configuration
    Registration Script
    Login Script
    Remember me feature for usename only
    Activation Script
    Retrieving forgotton Passwords and Username
    Resending Validation Email
    Logout Script
    Processing Member Commands

    All scripts to have a 32bit md5() password encryption and a sha 1() 40bit encryption to generate a 40 digit hash to use for the activation code.

    I would apprecaite any help. kaise@hotmail.co.uk

  • wal

    It’d be great if we post here any improvement on the security side for the code of this tutorial. Just like: change this “…..” for this “,,,,”.

  • Stew

    Hey,

    I keep can’t seem to find a solution to the following error:

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/oktxkldt/public_html/swhite5/testsite-users/login/index.php on line 33

    This is what I have for line 33:

    if(mysql_num_rows($checklogin) == 1)

    Not sure what part of this coding isn’t correct! Can anyone help?

    • Pascontent

      I had the same, until I double checked the table name, had it wrong ><

  • Ben

    Stew the error you’re getting is to do with the $checklogin MySQL query. Line 33 is fine, its the MySQL query that you’re trying to get a mysql_num_rows result from.

    $checklogin = mysql_query(“SELECT * FROM users WHERE Username = ‘”.$username.”‘ AND Password = ‘”.$password.”‘”);

    In most cases mysql_num_rows supplied argument error is to do with the MySQL query or if you provided a non-existent variable to get mysql_num_rows from. In this case I think its to do with the query. Add or die(mysql_error()) to the end of $checklogin query as shown above, and you’ll then find out if its the query:

    $checklogin = mysql_query(“SELECT * FROM users WHERE Username = ‘”.$username.”‘ AND Password = ‘”.$password.”‘”) or die(mysql_error());

    This will tell PHP if the query fails die and show me mysql_error. Just to let you know mysql_num_rows is to get number of rows in the database found by the query (i.e. “SELECT * FROM users WHERE username = ‘$username’” … asking if the user is in the database and if it is, mysql_num_rows will return 1. As there should only be 1 user of the same username in the database).

  • Rebecca

    I got the following error when I tested:

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL

    Can anyone help? I am very new to databases.

    • Rebecca

      Lol… I too finally figured out the problem, my mistake was in creating the database table on my server. I didn’t have it set up properly. :S

  • Ben D.

    I’m glad to see you using mysql_real_escape_string() but I would love to see input validation and parameter binding as well.

    Parameter-binding is conveniently available via the built-in PDO class as of PHP 5.1, for MySQL as well as any other backend database supported by PDO.

  • Bootta

    Thanks for tutorial. All is ok just one ” missing in logout.php after base.php

  • http://www.junglescripts.com/ Adam Winogrodzki

    i am having problem in database :S

  • Tay

    I am working on an assignment for class and I was wondering what code would I need to use to make sure that people login. on my homepage its has various links and if they click on one of the links across the top they can by pass login.

  • Lozz

    Brilliant tutorial

    especially for PHP beginners (like myself)

    as for leaving a few things out, it was a little challenge for me ;)

    overall though, fantastic

    thankyou!

  • Nykeri

    dood thank you this tut was great

  • http://www.atulthanvi.com Atul

    I don’t see any error in this tutorial. Its surely not of use when it comes to business websites but it will help to guide beginners

  • http://dixvi.se theo

    I´m getting an error in the logoutscript! Unexpected t_string (somethin like that)

  • http://tuts.cgbaran.com CgBaran Tuts

    Great tutorial thanks

  • http://www.acejunjiedesigns.net.tf ace

    Nice tutorial! Now i easily understand how to manage the session.
    Thanks

  • Me

    According to Programming PHP you should call session_regenerate_id( ); each time there is a change of privileges to prevent session fixation.

  • arnold C

    when I log in,my name and email address doesnt appear,why?but I succesfully log in..can someone help me

    • arnold C

      and your email address is .
      why the session doesnt appear?

    • arnold C

      nevermind I got it working already,,just a little bit of wrong code:)

      • ron

        I am getting the same thing i just can’t seem to see the error what did you do to solve this???

  • siddharth

    hi i am getting warning : Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at C:\x\htdocs\sign\index.php:2) in C:\x\htdocs\sign\base.php on line 4

    & u r logout.php is not working plz give fast reply & other wise u r code is working too good

  • http://www.rafaelrp.com.br/blog/ Rafael R.P (Raff)

    not work for me, when i loggin with my user name and passoword, he redirects from index.php and nothing happens, he calls back the login form and not the member area….

  • Pingback: 40+ Invaluable PHP Tutorials and Resources | Ouech.net

  • Christina

    Hi there,

    Having a problem…

    When a user enters their ‘members area’ page and
    the page displays: “Thanks for logging in! You are “” and your email address is “” .

    The position where the username and email is meant to display is not showing…I’ve pondered and tried to figure out the problem, but I’m stumped! I know it must have something to do with the variables maybe, but not sure!

    (This problem has been encountered with no modification to the source code whatsoever)

    Please help me out! aarrggghhhhhhhh!!!

    troubled, and biting nails!

    kind regards, Christina

  • http://www.demstudio.com.ar dem

    Guys… i really love this site… really :) All the Envato Network!

  • leo

    plan someone help me??? i want to creat an e-magazine like http://www.bakdergisi.com/index.php?sayfa=index&language=en

    if u go to the link and download the emagazine that is what i am looking for something similar to it!

    pls if anyone can help me i can reward for the time to help me tks

  • http://www.knowyourmactuts.com John

    Could someone possibly help me with something?

    I created the logout file, but since there was no link to logout in the code you gave us, I just added my own. But when I click it I get an error saying:

    Parse error: syntax error, unexpected T_STRING in /home/freeload/public_html/knowyourmactuts.com/members/logout.php on line 2

    Any ideas?