我在我的网站上有问题,它在我的本地服务器上完美地工作,这是一个WAMPSERVER,我可以完全运行我的网站,但在添加到web服务器后,它给我错误说
警告:session_start() [function. s]
:无法发送会话cookie - headers已经发送(输出开始于/home/multisl/public_html/udrivetest/index.php:2)在/home/multisl/public_html/udrivetest/init.php第4行init.php
<?php
ob_start();
session_start();
mysql_connect("localhost","***","***");
mysql_select_db('****');
include 'function/user.func.php';
include 'function/car.func.php';
include 'function/image.func.php';
?>
header1.php
<head>
<title></title>
<link href="css/style.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style4 {
font-size: 16px;
font-weight: bold;
}
.style5 {
font-size: 12px
}
.a {
color:#000000;
text-decoration:none;
}
-->
</style>
</head>
<body>
<div style="margin-left:10px;">U Drive.lk</div>
<div class="style5" style="text-align:right; padding:10px;">
Contact Us | Disclaimer | Site Map</div>
</div>
<div>
<div style="background-image:url(images/Car3.png); border:#FFFFFF; border-style:solid; border-width:2px; border-top:none; border-bottom:none; width:920px; height:450px; margin-left:auto; margin-right:auto;" align="center">
<br/>
<img src="images/Car6.png" width="920px" height="135px" />
<div style="margin-top:-22px; height:22px; margin-left:55px;" align="left"><a class="a">Home</a></div>
<div style="margin-top:-22px; height:22px; margin-left:200px;" align="left"><a class="a">Gallery</a></div>
<div style="margin-top:-22px; height:22px; margin-left:350px;" align="left"><a class="a">Leasing</a></div>
<div style="margin-top:-22px; height:22px; margin-left:490px;" align="left"><a class="a">Testimonial</a></div>
<div style="margin-top:-22px; height:22px; margin-left:640px;" align="left"><a class="a">Forum</a></div>
<div style="margin-top:-22px; height:22px; margin-left:790px;" align="left"><a class="a">FAQ</a></div>
<div style="margin-left:auto; margin-right:auto; margin-top:20px;" >
<script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','920','height','135','src','Flash/Flash Header2','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','Flash/Flash Header2' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="920" height="135">
<param name="movie" value="Flash/Flash Header2.swf" />
<param name="quality" value="high" />
<embed src="Flash/Flash Header2.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="920" height="135"></embed>
</object></noscript>
</div>
<div align="left">
<table width="100%" border="0" style="margin-top:10px;">
<tr>
<td width="20%" valign="top" ><div align="left"><img src="images/Buy_men.png" /> <img src="images/Sell_men.png" /> <img src="images/Rent_men.png" /></div>
<div style="color:#FFFFFF;margin-top:-90px; width:38px; margin-left:10px;"><a href="displayVehicle.php" style="color:#FFFFFF;">Buy</a></div>
<div style="color:#FFFFFF;margin-top:-18px; width:38px; margin-left:65px;"><a href="submitCar.php" style="color:#FFFFFF;">Sell</a></div>
<div style="color:#FFFFFF;margin-top:-20px; width:38px; margin-left:115px;"><a style="color:#FFFFFF;">Rent</a></div></td>
<td width="38%"><fieldset style="background-color:#cccccc">
<span class="style4">Quick Search</span>
</fieldset></td>
<td width="42%"><fieldset style="background-color:#cccccc">
<span class="style4">Login</span>
<?php include_once('login.php'); ?>
</fieldset></td>
</tr>
</table>
</div>
</div>
</div>
<div style="margin-left:auto; margin-right:auto; width:920px;">
login。
<?php
if (logged_in()) {
echo '<br/> <a href="personal_ViewPage.php"> View User Profile </a> <br/><a href="logout.php">Log Out</a>';
} else {
?>
<form action="" method="post">
<table width="100%" border="0" style="margin-top:-5px;" >
<tr>
<td><div align="left">User Name :</div></td>
<td><input type="text" name="Quick_Name" size="25" /></td>
</tr>
<tr>
<td><div align="left">Password :</div></td>
<td> <input type="text" name="PassWord" size="25" /> <input type="submit" value="Submit" /></td>
</tr>
</table>
</form>
<a href="forgotPassword.php">Forgot your password </a>/ <a href="user_Register.php">Register User</a>
<?php
}
if (isset($_POST['Quick_Name'], $_POST['PassWord'])) {
$forgotEmail = $_POST['Quick_Name'];
$login_password = $_POST['PassWord'];
if (empty($forgotEmail) || empty($login_password)) {
$errors[] = 'Email and Password required';
} else {
$login = login($forgotEmail, $login_password);
if ($login === false) {
$errors[] = 'Unable to Log you in';
}
}
if (!empty($errors)) {
foreach ($errors as $error) {
echo $error, '<br/>';
}
} else {
$_SESSION['user_id'] = $login;
header('Location:index.php');
exit();
}
}
?>
index . php
<?php include 'init.php'; include 'widgets/header1.php'; ?>
<div>
</div>
</div>
</body>
</html>
请问有谁能帮我解决这个问题,或者给我一个线索,我在这里做什么?
Thanks in Advance
在PHP中,页面一开始打印内容就会发送报头——这可能是由于空白而无意中发生的。
根据你的错误信息(输出开始于/home/multisl/public_html/udrivetest/index.php:2)
我猜这行index.php:
<?php include 'init.php'; include 'widgets/header1.php'; ?>
出现在文件的第2行?但是你不能在它上面有一行空白,它需要在第1行,因为其中一个包含正在处理标头(cookie for session)。
否则,空行1是"打印一些东西"——一个新的行——它可能在你想要之前发送标题。
基本上,检查所有文件的开始标签<?php
上面没有空行,结束标签?>
下面没有空行。
这很可能是在session_start命令之前发送了一些空白,尝试删除关闭PHP标记(?>)并报告结果。通过这样做,您可以消除它输出任何无效空白的可能性。
应该有一些空白发送回客户端。如果您的最后一行代码是php代码,那么留下php结束标记?>是一个很好的做法。
确保php的开始标签和结束标签前后没有任何空白
你可以通过ob_start()使用对象缓冲来阻止任何输出发送到客户端。将ob_start放在PHP代码的最开头可以节省您的时间。
我想考虑将ob_start()从init.php移到index.php。
谢谢