| A Complete Membership System |
pages (4): 1 [2] 3 4 |
|
|
Login Script (login.php)
<?php
session_start();
include 'config.php';
if(isset($_POST['login']))
{
$username = trim(addslashes($_POST['username']));
$password = md5(trim($_POST['password']));
$query = mysql_query("SELECT * FROM Users WHERE Username =
'$username' AND Password = '$password' LIMIT 1") or die(mysql_error());
$row = mysql_fetch_array($query);
// now we check if they are activated
if(mysql_num_rows($query) > 0)
{
if($row['Activated'] > 0)
{
$_SESSION['s_logged_n'] = 'true';
$_SESSION['s_username'] = $username;
$_SESSION['s_name'] = $row['Name'];
header("Location: member.php");
} else {
echo '
<html>
<head>
<title>Login</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="error"><p>Sorry, you must activate your account first.
Please check your email for the email.</p>
<p>Didn'."'".'t get your validation email? <a href="resend.php">Click
here</a> to resend the validation email.</p></div>
</body>
</html>
';
}
} else {
echo '
<html>
<head>
<title>Login</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="error"><p>There was an error processing your login, it
appears that your username and/or password was incorrect. Please try
again.</p>
<p>Didn'."'".'t get your validation email? <a href="resend.php">Click
here</a> to resend the validation email.</p>
</div>
</body>
</html>
';
}
} else {
?>
<html>
<head>
<title>Login</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="wrapper">
<div id="head">the login page</div><br>
<div id="main">
<p>You must login to view this page. Enter your username and
password below and hit submit:</p>
<form method="post" action="<?= $_SERVER['PHP_SELF'] ?>">
<p>Username:<br>
<input name="username" type="text" Cid="username">
<p>Password:<br>
<input name="password" type="password" id="password">
</p>
<p>
<input name="login" type="submit" id="login" value="Submit">
</p>
</form>
<p>Didn't get your validation email? <a href="resend.php">Click
here</a> to resend the validation email.</p>
<p>Need an account? <a href="register.php">Click here</a> to
register, it's completely free! </p>
</div>
</div>
</body>
</html>
<? } mysql_close($l); ?>
|
As you can probably guess, this script utilizes PHP
SESSIONS, so a session is started with the session_start()
command, and then config.php is included as before. We then
check whether the user has submitted the form or not. If they
have, it is processed, login details are checked, and the session
variables are set to confirm that he/she is logged in. If this is not
the case, the user is presented with a nice form instead. Nice and
simple!
Activation Script (activate.php) Not
many membership systems include activation scripts, but I wanted to show
you how to make yours “unspammable” and this is the easiest way. To put it
simply, the user must
enter a valid e-mail address otherwise he/she will not be able to validate their
account and will not be able to login! Its a nice way to ensure that all your
e-mail addresses are valid. Here’s the code you need:
<?php
include 'config.php';
$id = $_GET['id'];
$query = mysql_query("SELECT * FROM Users WHERE Actkey = '$id' LIMIT
1") or die(mysql_error());
$row = mysql_fetch_array($query);
if(mysql_num_rows($query) > 0){
$user = $row['id'];
$do = mysql_query("UPDATE Users SET Activated = 1 WHERE id = '$user'
LIMIT 1") or die(mysql_error());
$send = mail($row['Email'] , "Activation Confirmation" , "Thank you
for activating your account, you are now fully registered and able
to use our services.\n\nTo login, click the link below:\nhttp://CHANGETHISURL.COM/login.php"
, "FROM: auto@mailer.com");
if(($do)&&($send))
{
echo '<link href="style.css" rel="stylesheet" type="text/css">
<div id="success">
<p>Activation successful! A confirmation email has been dispatched.
You can now login!</p>
<p><a href="login.php">Click here</a> to goto the login page.</p>
</div>';
} else {
echo '<link href="style.css" rel="stylesheet" type="text/css">
<div id="error">
<p>We are sorry, there appears to be an error processing your
activation. Please try again later.</p>
</div>';
}
} else {
echo '<link href="style.css" rel="stylesheet" type="text/css">
<div id="error">
<p>Sorry, your activation code was incorrect. Please try again.</p>
</div>';
}
mysql_close($l);
?>
|
This script takes the header
variable “id” which is (when the script is run properly) a 40 character
sha1() hash of a randomly generated number and some random letters.
There is no need to process individual ID numbers in this script as we
can just search through the database to
find a user with the exact same activation key - the chances of two
users awaiting validation having the same hashed code is infinitesimally
small. Of course, once the appropriate user has been found,
his/her Activated value will be set to 1, thus activating/validating
them. If not, the
user gets an error message.
The most important thing to remember in this script is that you must
edit the mail() function and change the URL to your URL instead of the
text “CHANGETHISURL.COM” - otherwise the user will not know where or how
to login!
That was simple wasn't it? Activation is just
there so that the registration form can’t be spammed, and ensures an
authentic registrant. If
you want to be superior, you could write yourself an administration
panel with a function to delete all unactivated accounts that have been
sitting for X amount of time, because when you register, it logs the
date! This opens up a world of possibility for future modifications!
- Tutorial written by Scrowler
|

|
|
 |
PS Actions Question Author: MoodsR4Cattle Posted: Dec 03rd, 12:00am Activity: 3 replies, 35 views
|  | adobe photoshop cs4 Author: Rtouch Posted: Dec 02nd, 6:35pm Activity: 1 replies, 44 views
|  | High Quality Web Templates for low cost Author: JhonSmithi Posted: Dec 01st, 11:49am Activity: 0 replies, 41 views
|  | Metropolix washere .... Author: metropolix Posted: Nov 30th, 4:53am Activity: 0 replies, 71 views
|  | import vector art into paintshop pro? Author: agentxi Posted: Nov 29th, 12:27am Activity: 1 replies, 89 views
|  | Video Ranking Author: Nitewalker Posted: Nov 28th, 4:34pm Activity: 2 replies, 97 views
|  | Free Clipart and Illustrator Symbols Site Author: southoc Posted: Nov 28th, 4:29am Activity: 1 replies, 121 views
|  | i am looking for good quality of market place Author: ashuthosh Posted: Nov 27th, 6:19am Activity: 1 replies, 95 views
|  |
|
 |
 |
 |
 |
 |
| --- Site Resources --- |
| Total Tutorials: | 210 |
| Total Downloads: | 413 |
| Linkbase Links: | 243 |
 |
|
 |
 |
|