php文件在localhost上完美运行,但在webserver上却没有

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

Not sure if it's the cause - but I would change the include order to:

include('core/init.php'); 
include('navbar_teacher.php');
include('header.php');

as you have a session being started in core/init.php which must be started before any output.

http://php.net/manual/en/function.session-start.php#refsect1-function.session-start-notes


You could add a further check by testing that the session was actually created:

$sessionStarted = session_start();

if($sessionStarted)
{
    // code here
}
else
{
    // echo('Could not start session!');
}

I eventually found solution to the problem, thanks for all your contribution. I will alight where the problem was and the solution i profer which work perfectly. The problem was in the registration form and also the submit form

// the initial form

                                <div class="control-group">
                                <div class="controls">
                                 <ul>
<li>
<div class="control-group">
<label>UserName*:</label>
<input  type="text" name="username">
</div>
</li>
<li>
<div class="control-group">
<label>Password*:</label>:Hint-  Minimum 6 characters<br>
<input  type="password" name="password">
</div>
</li>
<li>
<div class="control-group">
<label>Password Again*:</label>
<input  type="password" name="password_again">
</div>
</li>
<li>
<div class="control-group">
<label>FirstName*:</label>
<input  type="text" name="first_name">
</div>
</li>
<li>
<div class="control-group">
<label>LastName:</label>
<input  type="text" name="last_name" />
</div>
</li>
<li>
<div class="control-group">
<label>Student's Class:</label>
<input  type="text" name="class" />
</div>

</li>
<li>
<div class="control-group">

<label>Unique Address:</label>
<input  type="text" name="mac" />
</div>

</li>
<li>
<div class="control-group">

<label>Phone Number:</label>
<input  type="text" name="phone_no" />
</div>
</li>
<li>
<div class="control-group">
<label>Email*:</label>
<input  type="text" name="email">
</div>
</li>

<li>
<div class="control-group">
<label>Contact Address:</label>
<textarea name="address"></textarea>
</div>
</li>
<input  type="submit" value="Register">
</li>
</ul>
</div>
                                        </div>
</form>

//the initial submit form

<?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);
}
?>

The problem was solved by adding 'email_code' to the form since on my table email_code was not defined to be 0 or 1. 'email_code' =>md5($_POST['username'] + microtime())

solution
 <li>
    <div class="control-group">
    <label>RE-Type Email*:</label>
    <input  type="text" name="email_code">
    </div>
    </li>

// the initial form

                                <div class="control-group">
                                <div class="controls">
                                 <ul>
<li>
<div class="control-group">
<label>UserName*:</label>
<input  type="text" name="username">
</div>
</li>
<li>
<div class="control-group">
<label>Password*:</label>:Hint-  Minimum 6 characters<br>
<input  type="password" name="password">
</div>
</li>
<li>
<div class="control-group">
<label>Password Again*:</label>
<input  type="password" name="password_again">
</div>
</li>
<li>
<div class="control-group">
<label>FirstName*:</label>
<input  type="text" name="first_name">
</div>
</li>
<li>
<div class="control-group">
<label>LastName:</label>
<input  type="text" name="last_name" />
</div>
</li>
<li>
<div class="control-group">
<label>Student's Class:</label>
<input  type="text" name="class" />
</div>

</li>
<li>
<div class="control-group">

<label>Unique Address:</label>
<input  type="text" name="mac" />
</div>

</li>
<li>
<div class="control-group">

<label>Phone Number:</label>
<input  type="text" name="phone_no" />
</div>
</li>
<li>
<div class="control-group">
<label>Email*:</label>
<input  type="text" name="email">
</div>
</li>
<li>
<div class="control-group">
<label>RE-Type Email*:</label>
<input  type="text" name="email_code">
</div>
</li>
<li>
<div class="control-group">
<label>Contact Address:</label>
<textarea name="address"></textarea>
</div>
</li>
<input  type="submit" value="Register">
</li>
</ul>
</div>
                                        </div>
</form>