| 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
|

|
|
 |
TrentonCS Author: ahstanford Posted: Nov 06th, 7:40pm Activity: 3 replies, 27 views
|  | Html 5 Author: ahstanford Posted: Nov 05th, 1:32pm Activity: 5 replies, 89 views
|  | What are your favorite websites? Author: ahstanford Posted: Nov 05th, 12:51am Activity: 0 replies, 47 views
|  | What do you do for a living? Author: ahstanford Posted: Nov 04th, 11:04pm Activity: 0 replies, 45 views
|  | What is your favorite Subway sandwich? Author: ahstanford Posted: Nov 04th, 11:02pm Activity: 4 replies, 88 views
|  | Windows 7 Author: ahstanford Posted: Nov 04th, 10:59pm Activity: 0 replies, 49 views
|  | Google Wave Author: ahstanford Posted: Nov 04th, 10:52pm Activity: 0 replies, 60 views
|  | University Project Author: Gjbphp Posted: Nov 03rd, 8:59pm Activity: 1 replies, 90 views
|  | Hello BioRust! Author: ahstanford Posted: Nov 02nd, 5:39pm Activity: 4 replies, 87 views
|  | Illustrator cs4 - Convert outlines/graphics to ... Author: izidrew Posted: Oct 29th, 3:48pm Activity: 3 replies, 259 views
|  | Hello BioRust!! Author: MOST Posted: Oct 29th, 12:52am Activity: 4 replies, 144 views
|  | Hey! newbie Author: prelimiting Posted: Oct 28th, 11:51pm Activity: 1 replies, 113 views
|  |
|
 |
 |
 |
 |
 |
| --- Site Resources --- |
| Total Tutorials: | 212 |
| Total Downloads: | 415 |
| Linkbase Links: | |
 |
|
 |
 |
|