2013-07-17 69 views
-4

我有一个简单的注册表单设置,发送详细信息到我的功能把数据放在数据库中我希望页面重定向到成功页面...PHP标头位置不在现场服务器上工作

这出色的作品我的本地服务器上,但是当我上传到我的直播服务器它只是不重定向

不工作重定向是第65行:)它只是重定向到register.php?成功

任何帮助将受到感谢。我见过几个人也有同样的问题,但他们的解决方案不会为我:(

所有其他头位置携手仅这一个不会:// @

<?php 
    include 'core/init.php'; 
    //check if logged in 
    logged_in_redirect(); 
    include 'includes/overall/header.php'; 

if (empty($_POST) === FALSE) { 
    $required_fields = array('username', 'password', 'password_again', 'first_name', 'last_name', 'email'); 
    foreach ($_POST as $key => $value) { 
     if (empty($value) && in_array($key, $required_fields) === true) { 
      $errors[] = 'You appear to have missed something out, all fields are required.'; 
      break 1; 

     } 
    } 

    if (empty($errors) === true) { 
     if (user_exists($_POST['username']) === true) { 
      $errors[] = 'Sorry, the username \'' . $_POST['username'] . '\' is already taken.'; 
     } 
     if (strlen($_POST['username']) < 6) { 
      $errors[] = 'Sorry, your username must be at least 6 characters.'; 
     } 
     if (strlen($_POST['username']) > 25) { 
      $errors[] = 'Sorry, your username must be under 25 characters.'; 
     } 
     if (preg_match("/\\s/", $_POST['username']) == true) { 
      $errors[] = 'Your username must not contain any spaces.'; 
     } 
     if (strlen($_POST['password']) < 6) { 
      $errors[] = 'Sorry, your password must be at least 6 characters.'; 
     } 
     if ($_POST['password'] !== $_POST['password_again']) { 
      $errors[] = 'Sorry, your passwords do not match.'; 
     } 
     if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) { 
      $errors[] = 'Sorry, you did not provide a valid email address.'; 
     } 
     if (email_exists($_POST['email']) === true) { 
      $errors[] = 'Sorry, the email \'' . $_POST['email'] . '\' is already registered to an account.'; 
     } 
    } 
} 

?> 
<h1>Register</h1> 

<?php 
if (isset($_GET['success']) && empty($_GET['success'])) { 
    echo "You have been registered successfully."; 
} else { 
    if (empty($_POST) === false && empty($errors) === true) { 
     // register user 
     $register_data = array(
      'username'  => $_POST['username'], 
      'password'  => $_POST['password'], 
      'first_name' => $_POST['first_name'], 
      'last_name'  => $_POST['last_name'], 
      'email'   => $_POST['email'], 
      'email_code' => md5($_POST['username'] + microtime()) 
     ); 

     register_user($register_data); 
     //header location not working ********************* 
     header('Location: register.php?success'); 
     exit(); 

    } else if (empty($errors) === false) { 
     //error output 
     echo output_errors($errors); 
    } 

?> 
    <form action="" method="post"> 
     Register your account here, all fields are required. 
     <ul> 
      <li> 
       Username: </br> 
       <input type="text" name="username"/> 
      </li> 
      <li> 
       Password: </br> 
       <input type="password" name="password"/> 
      </li> 
      <li> 
       Repeat Password: </br> 
       <input type="password" name="password_again"/> 
      </li> 
      <li> 
       First Name: </br> 
       <input type="text" name="first_name"/> 
      </li> 
      <li> 
       Last Name: </br> 
       <input type="text" name="last_name"/> 
      </li> 
      <li> 
       Email: </br> 
       <input type="text" name="email"/> 
      </li> 
      <li> 
       <input type="submit" value="Register"/> 
      </li> 
     </ul> 
    </form> 

<?php 
} 
include 'includes/overall/footer.php'; 


?> 
+5

我在打开'<?php'之前看到空格。删除它,因为它会阻止标题被发送。 - 哦,还有'

寄存器

'输出。在header()调用之前没有输出! –

+0

您是否在服务器错误日志中看到任何错误? – 2013-07-17 01:37:35

+0

显示响应标题。 – zerkms

回答

0

最有可能的,输出缓冲区在开发环境中处于开启状态,并且在现场环境中关闭,并且在用户环境中必须关闭显示用户错误,或者在浏览器中显示确切的错误(输出在标题之前开始)

检查你的ini文件这个东西:http://php.net/manual/en/outcontrol.configuration.php

0

请记住,必须在发送任何实际输出之前调用header(),或者使用普通的HTML标记,文件中的空行或PHP。使用include()或require()函数或其他文件访问函数读取代码,并在调用header()之前输出空格或空行是非常常见的错误。使用单个PHP/HTML文件时存在同样的问题。

+0

谢谢! :) 这是我的第一个大项目,迄今为止我学到了很多:) 我解决了这个问题,当我需要它的时候只包括头部,有点麻烦,但它的工作:D我会在整理之前收拾它我去住。 –

相关问题