dpnv33177 2017-01-18 15:07
浏览 191

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

  • 写回答

2条回答 默认 最新

  • doutinghou6980 2017-01-18 15:14
    关注

    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!');
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料