登录php页面不重定向

时间:2011-12-14 21:45:37

标签: login

我有一个使用Dreamweaver CS4创建的login.php页面。 在表单中输入用户名和密码后,页面重新加载自身而不是重定向到所需位置。 现有网站的网址:http://www.decoraflooringstore.com 单击客户端登录后,将打开登录页面 下面是php代码: 感谢您的任何输入

<?php require_once('Connections/test.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
   $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
     case "text":
         $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
         break;    
      case "long":
      case "int":
         $theValue = ($theValue != "") ? intval($theValue) : "NULL";
         break;
      case "double":
         $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
         break;
      case "date":
        $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
        break;
      case "defined":
         $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
         break;
  }
  return $theValue;
}
}

mysql_select_db($database_test, $test);
$query_Recordset1 = "SELECT `user`.`user name`, `user`.password FROM `user`";
$Recordset1 = mysql_query($query_Recordset1, $test) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
   session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
   $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['username'])) {
   $loginUsername=$_POST['username'];
   $password=$_POST['username'];
   $MM_fldUserAuthorization = "";
   $MM_redirectLoginSuccess = "success login.php";
   $MM_redirectLoginFailed = "failed login.php";
   $MM_redirecttoReferrer = false;
   mysql_select_db($database_test, $test);

   $LoginRS__query=sprintf("SELECT `user name`, password FROM `user` WHERE `user     name`=%s AND password=%s",
      GetSQLValueString($loginUsername, "-1"), GetSQLValueString($password, "text")); 

   $LoginRS = mysql_query($LoginRS__query, $test) or die(mysql_error());
   $loginFoundUser = mysql_num_rows($LoginRS);
   if ($loginFoundUser) {
      $loginStrGroup = "";

      //declare two session variables and assign them
      $_SESSION['MM_Username'] = $loginUsername;
      $_SESSION['MM_UserGroup'] = $loginStrGroup;         

      if (isset($_SESSION['PrevUrl']) && false) {
         $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];   
      }
      header("Location: " . $MM_redirectLoginSuccess );
   }
   else {
      header("Location: ". $MM_redirectLoginFailed );
   }
}
?>
<table width="500" border="0" align="center">
   <tr>
      <td><table width="400" border="0" align="center">
         <tr>
            <td>Username</td>
            <td><form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
               <label>
                 <input type="text" name="username" id="username" />
              </label>
            </form></td>
          </tr>
          <tr>
             <td>Password</td>
             <td><form id="form2" name="form2" method="post" action="">
                <label>
                   <input type="text" name="password" id="password" />
                </label>
             </form></td>
          </tr>
          <tr>
             <td>&nbsp;</td>
             <td><form id="form3" name="form3" method="post" action="">
               <label>
                <input type="submit" name="login" id="login" value="Login" />
               </label>
             </form></td>
          </tr>
       </table></td>
    </tr>
</table>
<?php
mysql_free_result($Recordset1);
?>

2 个答案:

答案 0 :(得分:0)

为了能够重定向,您必须避免发送以前的内容。否则,您将收到消息“已发送标题”。

命令session_start()将发送标头,不允许进一步重定向。

避免使用多个打开和关闭php标记。您将在结束标记和下一个开始标记之间发送换行符。这也会导致发送标头,不允许重定向按预期工作。

答案 1 :(得分:0)

使用isset函数检查用户名和密码。我在条件语句中 如果密码是对的 标题( “位置:的index.php”); 其他 标题( “位置:something.php”); 如果您的信息有效,它将重定向到index.php,如果无效,它将重定向到something.php