1.7. Registering a New User
With the directory structure laid out and enough of the support code written, the focus can now move to registering a new user. The following code can be saved in the public_files folder as register.php. Figure 1-2 shows the page viewed in a browser.
Figure 1-2. Figure 1-2
<?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 the CAPTCHA text stored in $_SESSION is // accessible session_start(); header('Cache-control: private'); // prepare the registration form's HTML ob_start(); ?> <form method="post" action="<?php echo htmlspecialchars($_SEVER['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'])) echo htmlspecialchars($_POST['username']); ?>"/></td> </tr><tr> <td><label for="password1">Password</label></td> <td><input type="password" name="password1" id="password1" value=""/></td> </tr><tr>
<td><label for="password2">Password Again</label></td> <td><input type="password" name="password2" id="password2" value=""/></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'])) echo htmlspecialchars($_POST['email']); ?>"/></td> ...
Get PHP and MySQL®: Create-Modify-Reuse now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.