Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Important variables
- $username = $_POST['username'];
- $password = $_POST['password'];
- $file = "users.txt";
- $text = "\n$username\n$password\n";
- /////////////////////////////////////////////////////////
- //Checks input for blank entrys//////////////////////////
- function check_for_blank_entries ($check, $text)
- {
- if($check == NULL)
- {
- echo $text;
- return(FALSE);
- }
- else
- {
- return(TRUE);
- }
- }
- $username_check_blank = check_for_blank_entries($username, 'Username cannot be blank.<br><br>');
- $password_check_blank = check_for_blank_entries($password, 'Password cannot be blank.<br><br>');
- /////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////
- //Checks for only numbers and letters
- function check_for_correct_values($check, $text)
- {
- if (! eregi("^[a-zA-Z0-9]*$", $check) )
- {
- echo $text;
- return(FALSE);
- }
- else
- {
- return(TRUE);
- }
- }
- $username_check_value = check_for_correct_values($username, 'Username contains invalid characters.<br><br>');
- $password_check_value = check_for_correct_values($password, 'Password contains invalid characters.<br><br>');
- //////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////
- //Check if username and password exists.
- function check_files($check, $text)
- {
- $scan = file('users.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
- if (in_array("$check", $scan))
- {
- echo $text;
- return(FALSE);
- }
- else
- {
- return(TRUE);
- }
- }
- $username_check = check_files($username, 'Username is already in use.<br><br>');
- $password_check = check_files($password, 'Password is already in use.<br><br>');
- /////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////
- //Add new user to the list.
- if($username_check_blank && $password_check_blank && $username_check && $password_check && $username_check_value && $password_check_value == FALSE)
- {
- file_put_contents($file, $text, FILE_APPEND);
- echo 'You have been registered successfully.<br><br>';
- }
- else
- {
- echo 'not going to register';
- }
- /////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement