让我的PHP表单在服务器上工作

时间:2012-05-03 19:28:20

标签: php html dreamweaver

  

可能重复:
  Headers already sent by PHP

  

警告:session_start()[function.session-start]:无法发送会话cookie - 在D:\ USBWebserver_v8_en中已经发送的标题(在D:\ USBWebserver_v8_en \ root \ pages \ login.php:1处开始输出)第0行的root \ pages \ login.php

我创建了一个带有html代码的登录表单,我的服务器都设置了所有设置和所有东西,我使用USB Webserver V8,它有phpmyadmin功能,所以我已经创建了一个数据库,使用Dreamweaver链接数据库字段和内容,然后我使用了Dream weaver上的登录验证字段功能,以便将页面转到成功或失败的位置。

当我在服务器上打开它时,在输入任何内容之前我会收到以下错误

警告:session_start()[function.session-start]:无法发送会话cookie - 在D:\ USBWebserver_v8_en中已经发送的标题(在D:\ USBWebserver_v8_en \ root \ pages \ login.php:1处开始输出)第0行的root \ pages \ login.php

警告:session_start()[function.session-start]:无法发送会话缓存限制器 - 已在D:\ USBWebserver_v8_en中发送的标头(输出从D:\ USBWebserver_v8_en \ root \ pages \ login.php:1开始)第0行的root \ pages \ login.php

警告:session_regenerate_id()[function.session-regenerate-id]:无法重新生成会话ID - 已在第62行的D:\ USBWebserver_v8_en \ root \ pages \ login.php中发送的标头

当输入内容时,不会发生验证,我也会收到另一条消息 警告:无法修改标题信息 - 已在第70行的D:\ USBWebserver_v8_en \ root \ pages \ login.php中发送的标题(输出从D:\ USBWebserver_v8_en \ root \ pages \ login.php:1开始)

这是我表格上的代码

<form METHOD="POST" action="<?php echo $loginFormAction; ?>" id="form2">
<p>&nbsp;</p>
<p><span class="letter">Username:</span>
<input type="text"name="username""username id="username"">
</p>
<p><span class="letter">Password: </span>
<input type="password"name="password"/>
</p>
<p>
<input name="submit" type="submit" class="content1" value="Login" />
</p>
<p>&nbsp;</p>
<!-- end .content -->
</form>

这是我的PHP代码

<?php virtual('/Connections/reuben1.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;
}
}
?>
<?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['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "/Pages/Home.html";
$MM_redirectLoginFailed = "/Pages/Help.html";
$MM_redirecttoReferrer = false;
mysql_select_db($database_reuben1, $reuben1);

$LoginRS__query=sprintf("SELECT username, passwowrd FROM users WHERE username=%s AND   passwowrd=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 

$LoginRS = mysql_query($LoginRS__query, $reuben1) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
//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 );
}
}
?>

我不知道为什么它不起作用:(

2 个答案:

答案 0 :(得分:0)

查看D的第1行:\ USBWebserver_v8_en \ root \ pages \ login.php

正在输出那些正在停止启动会话的东西。在打开php标记之前,这可能是空行或空格

答案 1 :(得分:0)

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent

这意味着PHP已经向浏览器输出了一些数据,这意味着它无法设置任何标头(在发送任何HTML之前设置的内容)。在这种情况下,通常意味着在第一个打开PHP标记之前存在一些代码。在login.php中,确保在第一个打开PHP标记之前 - 甚至空白(空格,新行等)。同样的规则适用于/Connections/reuben1.php - 确保在它的开头没有任何空格。