页面将不会重定向到正确的页面

问题描述:

我上传了一个登录/注册网站Godaddy出于某种原因页面将不能正确重定向,它可以在本地主机上正常测试,任何帮助将不胜感激!页面将不会重定向到正确的页面

这是我的register.php页面代码:你header()调用之前

<!doctype html> 
<html lang="en"> 
<head> 
<title>Register page</title> 
<meta charset=utf-8> 
<link rel="stylesheet" type="text/css" href="includes.css"> 
<style type="text/css"> 
p.error { color:red; font-size:105%; font-weight:bold; text-align:center;} 
</style> 
</head> 
<body> 
<div id="container"> 
<?php include("register-header.php"); ?> 
<?php include("nav.php"); ?> 
<?php include("info-col.php"); ?> 
    <div id="content"><!-- Start of the register page content --> 
<p><?php 
require ('mysqli_connect.php'); // Connect to the database. 
// If the form has been submitted, insert a record in the users table 
if ($_SERVER['REQUEST_METHOD'] == 'POST') { 
    $errors = array(); // Initialize an error array 
    // Check for a first name: 
    if (empty($_POST['fname'])) { 
     $errors[] = 'You forgot to enter your first name.'; 
    } else { 
     //$fn = trim($_POST['fname']); 
      $fn = mysqli_real_escape_string($dbcon, trim($_POST['fname'])); 
    } 
    // Check for a last name: 
    if (empty($_POST['lname'])) { 
     $errors[] = 'You forgot to enter your last name.'; 
    } else { 
     //$ln = trim($_POST['lname']); 
     //$ln = mysqli_real_escape_string($dbcon, $ln); 
     $ln = mysqli_real_escape_string($dbcon, trim($_POST['lname'])); 
    } 
    // Check for an email address 
    if (empty($_POST['email'])) { 
     $errors[] = 'You forgot to enter your email address.'; 
    } else { 
     $e = trim($_POST['email']); 
    } 
    // Check for a password then match it against the confirmed password: 
    if (!empty($_POST['psword1'])) { 
     if ($_POST['psword1'] != $_POST['psword2']) { 
      $errors[] = 'Your two password did not match.'; 
     } else { 
      $p = mysqli_real_escape_string($dbcon, trim($_POST['psword1'])); 
     } 
    } else { 
     $errors[] = 'You forgot to enter your password.'; 
    } 
    if (empty($errors)) { // If everything's OK 
    // Register the user in the database... 
     // Make the query: 
     $q = "INSERT INTO users (user_id, fname, lname, email, psword, registration_date) VALUES (' ', '$fn', '$ln', '$e', SHA1('$p'), NOW())";   
     $result = @mysqli_query ($dbcon, $q); // Run the query. 
     if ($result) { // If it ran OK 
     header ("location: register-thanks.php"); 
     exit(); 
     // Echo a message: 
     //echo '<h2>Thank you!</h2> 
     //<p>You are now registered.</p><p><br></p>'; 
     } else { // If it did not run OK 
     // Error message: 
      echo '<h2>System Error</h2> 
      <p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'; 
      // Debugging message: 
      echo '<p>' . mysqli_error($dbcon) . '<br><br>Query: ' . $q . '</p>'; 
     } // End of if ($result) 
     mysqli_close($dbcon); // Close the database connection. 
     // Include the footer and stop the script 
     include ('footer.php'); 
     //header ("location: register-thanks.php"); 
     //exit(); 
    } else { // Report the errors 
     echo '<h2>Error!</h2> 
     <p class="error">The following error(s) occurred:<br>'; 
     foreach ($errors as $msg) { // Echo each error 
      echo " - $msg<br>\n"; 
     } 
     echo '</p><h3>Please try again.</h3><p><br></p>'; 
     }// End of if (empty($errors)) 
} // End of the main Submit conditional 
?> 
<h2>Register</h2> 
<form action="register-page.php" method="post"> 
    <p><label class="label" for="fname">First Name:</label><input id="fname" type="text" name="fname" size="30" maxlength="30" value="<?php if (isset($_POST['fname'])) echo $_POST['fname']; ?>"></p> 
    <p><label class="label" for="lname">Last Name:</label><input id="lname" type="text" name="lname" size="30" maxlength="40" value="<?php if (isset($_POST['lname'])) echo $_POST['lname']; ?>"></p> 
    <p><label class="label" for="email">Email Address:</label><input id="email" type="text" name="email" size="30" maxlength="60" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" > </p> 
    <p><label class="label" for="psword1">Password:</label><input id="psword1" type="password" name="psword1" size="12" maxlength="12" value="<?php if (isset($_POST['psword1'])) echo $_POST['psword1']; ?>" >&nbsp;Between 8 and 12 characters.</p> 
    <p><label class="label" for="psword2">Confirm Password:</label><input id="psword2" type="password" name="psword2" size="12" maxlength="12" value="<?php if (isset($_POST['psword2'])) echo $_POST['psword2']; ?>" ></p> 
    <p><input id="submit" type="submit" name="submit" value="Register"></p> 
</form> 
<?php include ('footer.php'); ?></p> 
    <!-- End of the register page content --> 
</div> 
</div> 
</body> 
</html> 
+2

打开错误报告,它可能会给你一个提示。另外,当你遇到困难时,尝试创建一个能够重现问题的最小例子。在这种情况下,如果你试图做一个重定向,你会发现它的工作原理。所以,这个问题是别的......开始隔离和测试。你在这里做的是在我们身上扔了一大堆代码,然后说:“为什么它没有做我想要的?” - 你永远不会像这样学习。 – 2014-09-18 16:54:08

你有输出。在它之前必须有绝对的输出。如果你打开错误报告,你可能会看到一个关于“Headers already sent”的警告。

将您的登录代码移到页面的绝对开头,存储任何消息供以后显示。

+0

非常感谢您的帮助! – Daniel 2014-09-18 22:21:02