topical media & game development
professional-sql-02-public-files-register.php / php
<?php
// include shared code
include '../lib/common.php';
include '../lib/db.php';
include '../lib/functions.php';
include '../lib/User.php';
// start or continue session so we can access captcha text stored in
session_start();
// prepare the registration form
ob_start();
?>
<form method="post"
action="<?php echo htmlspecialchars(_SERVER['PHP_SELF']); ?>">
<table>
<tr>
<td><label for="username">Username</label></td>
<td><input type="text" name="username" id="username"
value="<?php if (isset(_POST['username']); ?>"/></td>
</tr><tr>
<td><label for="password1">Password</label></td>
<td><input type="passowrd" name="password1" id="password1"
value="<?php if (isset(_POST['password1']); ?>"/></td>
</tr><tr>
<td><label for="password2">Password Again</label></td>
<td><input type="password" name="password2" id="password2"
value="<?php if (isset(_POST['password2']); ?>"/></td>
</tr><tr>
<td><label for="email">Email Address</label></td>
<td><input type="text" name="email" id="email"
value="<?php if (isset(_POST['email']); ?>"/></td>
</tr><tr>
<td><label for="captcha">Verify</label></td>
<td>Enter text seen in this image<br/ >
<img src="img/captcha.php?nocache=<?php echo time(); ?>" alt=""/><br />
<input type="text" name="captcha" id="captcha"/></td>
</tr><tr>
<td> </td>
<td><input type="submit" value="Sign Up"/></td>
<td><input type="hidden" name="submitted" value="1"/></td>
</tr><tr>
</table>
</form>
<?php
_POST['submitted']))
{
form;
}
// otherwise process incoming data
else
{
// validate password
_POST['password1'])) ? password2 = (isset(_POST['password2'] : '';
password1 && password2) ?
sha1(captcha = (isset(_POST['captcha']) == _POST['username']) && password &&
User::validateEmailAddr(captcha)
{
// make sure the user doesn't already exist
_POST['username']);
if (GLOBALS['TEMPLATE']['content'] = '<p><strong>Sorry, that ' .
'account already exists.</strong></p> <p>Please try a ' .
'different username.</p>';
form;
}
else
{
// create an inactive user record
user->username = user->password = user->emailAddr = token = GLOBALS['TEMPLATE']['content'] = '<p><strong>Thank you for ' .
'registering.</strong></p> <p>Be sure to verify your ' .
'account by visiting <a href="verify.php?uid=' .
token . '">verify.php?uid=' .
token . '</a></p>';
}
}
// there was invalid data
else
{
GLOBALS['TEMPLATE']['content'] .=
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.