Here is code from one of my join pages. Pull from it what you will.
[php]<?php
/*
- Add Data
- Last Modified 4/3/2016 6:14 PM
*/
require(’./config.php’);
//----------------------------------------------------------------------------
// Allow direct access to this page
//----------------------------------------------------------------------------
define(‘securepage’, true);
//----------------------------------------------------------------------------
// Page Header
//----------------------------------------------------------------------------
require(’./includes/header.php’);
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
$show_error = false;
if ($_POST)
{
//------------------------------------------------------------------------
// Trim Data, Check Missing Fields
//------------------------------------------------------------------------
include('./includes/validate_registration.php');
//------------------------------------------------------------------------
// Check for errors
//------------------------------------------------------------------------
if ($error)
{
$show_error = true;
}
else
{
// generate 16 random bytes
$raw_token = mcrypt_create_iv(16, MCRYPT_DEV_URANDOM);
// encode the random bytes and send the result to the user
$encoded_token = bin2hex($raw_token);
// hash the random bytes and store this hash in the database
$token_hash = hash('sha256', $raw_token);
$hashed_password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$sql = "INSERT INTO users (email, password, activation_key) values(?,?,?)";
$stmt = $pdo->prepare($sql);
$stmt->execute(array(
$_POST['email'],
$hashed_password,
$token_hash
));
$msg = 'activate';
$activation_msg = "Activation Link $url_website/activate.php?k=$encoded_token";
if (@!mail("{$_POST['email']}", "Activation Information", $activation_msg, "From: $email_from\r\n"))
{
/* error_get_last() Array
* [type] => 2
* [message] => mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
* [file] => E:\Zend\Apache2\htdocs\projects\mysite\join.php
* [line] => 60
*/
$error = error_get_last();
// If no mail server, log the failed mail error
if (LOG_ERROR == 1)
{
error_log("$mysql_datetime|{$error['message']} File: {$error['file']} Line: {$error['line']}\r\n", 3, "$errorlog_path");
} //LOG_ERROR == 1
die("There was a problem sending activation email. Please contact support.");
}
die(header("Location: login.php?activate"));
} // End Else
} // End POST
//--------------------------------------------------------------------
// Display Logo
//--------------------------------------------------------------------
logo();
//--------------------------------------------------------------------
// Display Form Errors
//--------------------------------------------------------------------
if ($show_error)
{
show_form_errors($error);
}
//--------------------------------------------------------------------
// Display Form
//--------------------------------------------------------------------
?>
<?php
include('./includes/footer.php');
?>[/php]