Hello. I have a two problems with my Regsystem.
1st. Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\mycms\reg.php:229) in C:\xampp\htdocs\mycms\reg.php on line 266
2nd: When i Register a user - system message "Username already exist" not "Registration succesfull"..
this is the code of register.php
<?php
require 'core/init.php';
$general->logged_in_protect();
if (isset($_POST['submit'])) {
if(empty($_POST['username']) || empty($_POST['password']) || empty($_POST['email'])){
$errors[] = 'All fields are required.';
}else{
if ($users->user_exists($_POST['username']) === true) {
$errors[] = 'That username already exists'; // ALWAYS TYPED THIS
}
if(!ctype_alnum($_POST['username'])){
$errors[] = 'Please enter a username with only alphabets and numbers';
}
if (strlen($_POST['password']) <6){
$errors[] = 'Your password must be atleast 6 characters';
} else if (strlen($_POST['password']) >18){
$errors[] = 'Your password cannot be more than 18 characters long';
}
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) {
$errors[] = 'Please enter a valid email address';
}else if ($users->email_exists($_POST['email']) === true) {
$errors[] = 'That email already exists.';
}
}
if(empty($errors) === true){
$username = htmlentities($_POST['username']);
$password = $_POST['password'];
$email = htmlentities($_POST['email']);
$users->register($username, $password, $email);
header('Location: reg.php?success');
exit();
}
}
?>
<?php
if (isset($_GET['success']) && empty($_GET['success'])) {
echo 'Thank you for registering. Please check your email.';
}
?>