Good day everyone, I have been battling with an issue for quite some months now. I have a php program that work perfectly on the localhost but one of the php files refuses to work on the webserver .ie. on my website after uploading. All other php files worked but the register.php files refuses to work on the webserver. what might likely be the cause. I am doing anything wrong. Kindly assit.
// register.php code
<?php
include('header.php');
include('navbar_teacher.php');
include 'core/init.php';
logged_in_redirect();
if (empty($_POST) === false) {
$required_fields = array('username ','password','password_again','first_name','class','mac','phone_no','email','js1','js2','address');
foreach ($_POST as $key=>$value) {
if (empty($value) && in_array($key, $required_fields) === true) {
$errors[] = 'Fields marked with an asterisk are required';
break 1;
}
}
if (empty($errors) === true) {
if (user_exists($_POST['username']) === true) {
$errors[] = 'Sorry, the username \''. $_POST['username'].'\' is already taken.';
}
if (preg_match("/\\s/", $_POST['username']) === true) {
$errors[] = 'Your username must not contain any space.';
}
if (strlen($_POST['password']) < 6 ) {
$errors[] = 'Your password must be at least 6 characters.';
}
if ($_POST['password'] !== $_POST['password_again']) {
$errors[] = 'Your password do not match.';
}
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)=== false) {
$errors[] = 'A valid email address is required';
}
if (email_exists($_POST['email']) === true) {
$errors[] = 'Sorry, the email \''. $_POST['email'].'\' is already in use.';
}
}
}
?>
<?php
if (isset($_GET ['success'])=== true && empty($_GET['success'])=== true) {
echo 'You\'ve been registered successfully! Please check your email to activate your account.';
}else {
if (empty($_POST) === false && empty($errors) === true) {
$register_data =array(
'username' => $_POST['username'],
'password' => $_POST['password'],
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'class' => $_POST['class'],
'mac' => $_POST['mac'],
'phone_no' => $_POST['phone_no'],
'email' => $_POST['email'],
'address' => $_POST['address'],
'email_code' =>md5($_POST['username'] + microtime())
);
register_user($register_data);
//header('Location: register.php?success');
echo("<script>location.href = 'register.php?success=$msg';</script>");
exit();
} else if (empty($errors) === false) {
echo output_errors($errors);
}
?>
<body id="class_div">
<div class="span8" id="content">
<div class="row-fluid">
<?php include('about.php'); ?>
</div>
</div>
<div class="row-fluid">
<div class="span4">
<?php include 'add_register.php';?> <!-- block -->
</body>
</html>
<?php
}
include 'includes/overall/footer.php';?>
//init.php code
<?php
session_start();
//error_reporting(0);
require 'database/connect.php';
require 'functions/general.php';
require 'functions/users.php';
$current_file = explode('/', $_SERVER['SCRIPT_NAME']);
$current_file = end($current_file);
if(logged_in() === true) {
$session_user_id = $_SESSION['user_id'];
$user_data = user_data($session_user_id, 'user_id','username','password','first_name', 'last_name','class','mac','phone_no','email','address','email_code','active','password_recover','type','allow_email','profile');
if (user_active($user_data['username']) === false) {
session_destroy();
//header('Location: index.php');
echo("<script>location.href = 'index.php=$msg';</script>");
exit();
}
if ($current_file !== 'changepassword.php' && $user_data['password_recover']== 1) {
header('Location: changepassword.php?force');
exit();
}
}
//echo $user_data['type'];
$errors = array();
?>
//users.php code
<?php
function register_user($register_data) {
array_walk($register_data, 'array_sanitize');
$register_data['password'] =md5($register_data['password']);
$fields = '`' . implode('`, `', array_keys($register_data)) . '`';
$data = '\'' . implode('\', \'', $register_data) . '\'';
$db->query(("INSERT INTO `users` ($fields) VALUES ($data)");
email($register_data['email'], 'Activate your account', "Hello " . $register_data ['first_name'] . ",
You need to activate your account, so use the link below:
http://ckischools.org/personal/activate.php?email=" . $register_data['email'] . "&email_code=" .$register_data['email_code'] . "
-ckischools ");
}
All other php files worked perfectly well on the server except the register.php which has a link with init.php and users.php