| A Complete Membership System |
pages (4): 1 2 [3] 4 |
|
|
Members Page (member.php) This is the page
the user will be shown when they log in. In my code I have separated all the
menu structure into a separate file, menus.php, and added it back in by
way of an INCLUDE to keep the source code below as simple as possible. You can either use the same code/idea in your script
or make your own navigation, but you need to make sure that the following 3
links are included to make use of the inbuilt
features in this members only page:
member.php?change=password – This will show a form to change your
password
member.php?change=email – This will show a form to change your email
address.
Note: both of the features above deactivate the user when the script processes,
and they must re-activate via email.
member.php?change=account – This will shut the account down & delete it.
This shows a confirmation message before referring itself to processing for
account deletion (see processing.php for more details).
<?php
session_start();
if($_SESSION['s_logged_n'] == 'true'){
include 'process.php';
?>
<html>
<head>
<title>Members Page</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="wrapper">
<div id="head">The member page</div><br>
<div id="container">
<? include 'menus.php' ?>
</div>
<div id="spacer"> </div>
<div id="memmain">
<?php
switch($_GET['change']){
case 'password':
echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<p>Current password:<br>
<input name="current" type="password"></p>
<p>New password:<br>
<input name="new" type="password"></p>
<p>Confirm new password:<br>
<input name="confirm" type="password"></p>
<p><input type="submit" value="Change Password" name="changepassword"></p>
</form>
';
break;
case 'email':
echo '<p>
WARNING! - By changing your email address you will have to
re-validate. Make sure you email address is 100% correct.</p>
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<p>Current email:<br>
<input name="current" type="text"></p>
<p>New email:<br>
<input name="new" type="text"></p>
<p>Confirm new email:<br>
<input name="confirm" type="text"></p>
<p><input type="submit" value="Change Email" name="changeemail"></p>
</form>
';
break;
case 'account':
echo '<p>
WARNING - By closing your account, you will not be able to login
again under this account. Press the button below to confirm you wish
to close your account</p>
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<p><input type="submit" value="Close Account" name="closeaccount"></p>
</form>
';
break;
default:
echo '<p>Welcome to the super secret members only control
panel!</p>';
}
?>
</div>
</body>
</html>
<?php
} else {
header("Location: login.php");
}
?>
|
The first
crucial IF statement checks the session containing data to ensure that
the user is allowed to view the page. If the user is properly
authenticated, the page will be shown. Otherwise, the page will re-refer
to the login.
The rest of the main page is pretty simple and you can structure it how
you like - providing, of course, that you include the appropriate links
mentioned above. Adding extra options is as easy as adding a few lines
of code to the switch. The switch
statement chooses what to do depending on the header variable “change”.
It has 3 inbuilt forms and a default clause which initiates when $_GET[‘change’]
is empty.
Resending Validation E-Mails (resend.php)
When running a script system that features user authentication, one essential
feature is a script that resends the validation e-mail, ensuring that if the
e-mail doesn't reach the recipient (due to network connectivity problems,
over-eager anti-spam systems, etc) then it can be re-sent with ease by simply
filling out a form.
<?php
include 'config.php';
if(isset($_POST['resend']))
{
$email = trim($_POST['email']);
$query = mysql_query("SELECT Actkey FROM Users WHERE Email =
'$email' LIMIT 1") or die(mysql_error());
while($row = mysql_fetch_array($query)){
$act = $row['Actkey'];
if(mysql_num_rows($query) > 0)
{
$send = mail($email , "Activate your account" , "Thank you for
registering with YourWebsite.\n\nClick the link below to activate
your account:\nhttp://CHANGETHISURL.COM/activate.php?id=".$act."\n\nPlease
do not reply, this is an automated mailer.\n\nThanks", "FROM: auto@mailer.com");
if($send){
echo '
<html>
<head>
<title>Success</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="wrapper">
<div id="head">the resend activation email page</div>
<br>
<div id="success">
<p>The validation email was successfully sent. <a href="login.php">Click
here</a> to login once you have activated.</p>
</div>
</div>
</body>
</html>
';
} else {
echo '
<html>
<head>
<title>Error</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="wrapper">
<div id="head">the resend activation email page</div>
<br>
<div id="error">
<p>Ha, what an act. There has been an error processing your
activation email. Please contact the administrator.</p>
</div>
</div>
</body>
</html>
';
}
} else {
echo '
<html>
<head>
<title>Error</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="wrapper">
<div id="head">the resend activation email page</div>
<br>
<div id="error">
<p>Sorry, your email was not found in the database, please enter an
email address that you have registered with and not recieved and
email with.</p>
</div>
</div>
</body>
</html>
';
}
}
} else {
?>
<html>
<head>
<title>Resend validation email</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="wrapper">
<div id="head">the resend activation email page</div>
<br>
<div id="main">
<p>Ok, so your activation email didn't get sent? DAMN S**T C*H(#@
((@J no, stop swearing, put that bottle down. You don't need it. We
need each other. I'm here to resend your email, so enter your email
address, and I will send the validation link to that email, provided
you have registered ofcourse, if you are trying to hack me, what a
sad guy, taking advantage of my emotions like that... jeez.</p>
<form method="post" action="<?= $_SERVER['PHP_SELF'] ?>">
<p>Email:<br>
<input name="email" type="text">
<p>
<input name="resend" type="submit" id="resend" value="Resend">
</form>
</p>
Once you enter your email and hit resend, I will make sure your
email is valid, then send you out your validation link. If it
doesn't come, try me again! I'm not a one night stand you know...
<p>By the way, I am very (case) sensitive so enter the email exactly
as you registered with it. </p>
</div>
</div>
</body>
</html>
<? } mysql_close($l); ?>
|
As you can probably deduce, this script features a
logic switch, meaning that when the user first loads the page they will
be shown a form, and when they submit the data, the page will process
that data instead. This involves searching
the database for the user account with the email address provided. If it
is found, an e-mail is sent to the appropriate e-mail address with the user’s
activation key in a URL that they can activate. As before, though, you
must change that URL in the mail() function to reflect your server's
settings!
If the email address isn’t found the user gets an error message. You may have noticed I use PHP_SELF as the form method in all the forms so far
- That is basically
just telling the form to process onto itself. Its a convenient
method that reduces the overall number of scripts needed for the whole
membership system.
- Tutorial written by Scrowler
|

|
|
 |
php, shoutbox problems Author: vanhansen Posted: Nov 17th, 1:30am Activity: 5 replies, 93 views
|  | MarkupGeeks Logo Author: ahstanford Posted: Nov 16th, 8:45pm Activity: 12 replies, 161 views
|  | Drawing Tutorials Author: ahstanford Posted: Nov 16th, 12:46am Activity: 0 replies, 100 views
|  | Superbowl predictions, anyone? Author: ahstanford Posted: Nov 15th, 10:46pm Activity: 10 replies, 138 views
|  | Photomanipulation Footsteps Author: ahstanford Posted: Nov 15th, 10:43pm Activity: 4 replies, 102 views
|  | Learning to draw... Author: ahstanford Posted: Nov 15th, 12:43pm Activity: 4 replies, 116 views
|  | Looking for simple UI elements Author: FenixRoA Posted: Nov 15th, 6:40am Activity: 7 replies, 109 views
|  | HDD Help? Author: Phoenix Wynde Posted: Nov 13th, 2:31am Activity: 1 replies, 107 views
|  | Fun New Battles Posted! Author: ahstanford Posted: Nov 11th, 7:33pm Activity: 0 replies, 141 views
|  | 4-man Simon Tournament Author: ahstanford Posted: Nov 11th, 3:28pm Activity: 0 replies, 92 views
|  | Design Brief Inspiration for BioRUST Battles! Author: ahstanford Posted: Nov 11th, 7:19am Activity: 4 replies, 140 views
|  | The BioRUST Free Stock Photography Thread Author: ahstanford Posted: Nov 11th, 6:32am Activity: 2 replies, 148 views
|  |
|
 |
 |
 |
 |
 |
| --- Site Resources --- |
| Total Tutorials: | 212 |
| Total Downloads: | 415 |
| Linkbase Links: | |
 |
|
 |
 |
|