Skip to content

Instantly share code, notes, and snippets.

@bradp
Created January 14, 2014 05:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bradp/8413360 to your computer and use it in GitHub Desktop.
Save bradp/8413360 to your computer and use it in GitHub Desktop.
dont_do_this
<?php
//dis like the best code ever
function register()
{
if (!empty($_POST)) {
$msg = '';
if ($_POST['user_name']) {
if ($_POST['user_password_new']) {
if ($_POST['user_password_new'] === $_POST['user_password_repeat']) {
if (strlen($_POST['user_password_new']) > 5) {
if (strlen($_POST['user_name']) < 65 && strlen($_POST['user_name']) > 1) {
if (preg_match('/^[a-z\d]{2,64}$/i', $_POST['user_name'])) {
$user = read_user($_POST['user_name']);
if (!isset($user['user_name'])) {
if ($_POST['user_email']) {
if (strlen($_POST['user_email']) < 65) {
if (filter_var($_POST['user_email'], FILTER_VALIDATE_EMAIL)) {
create_user();
$_SESSION['msg'] = 'You are now registered so please login';
header('Location: ' . $_SERVER['PHP_SELF']);
exit();
} else $msg = 'You must provide a valid email address';
} else $msg = 'Email must be less than 64 characters';
} else $msg = 'Email cannot be empty';
} else $msg = 'Username already exists';
} else $msg = 'Username must be only a-z, A-Z, 0-9';
} else $msg = 'Username must be between 2 and 64 characters';
} else $msg = 'Password must be at least 6 characters';
} else $msg = 'Passwords do not match';
} else $msg = 'Empty Password';
} else $msg = 'Empty Username';
$_SESSION['msg'] = $msg;
}
return register_form();
}
@davidkryzaniak
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment