2012-11-07 129 views
0

我有一个PHP代码。当我运行的代码,它的工作正常,但出现一些警告,那是 - Warning: Cannot modify header information - headers already sent by (output started at /home/fundumob/public_html/app_create/nav_class.php:119) in /home/fundumob/public_html/app_create/profile.php on line 32忽略PHP警告

我该怎么办? ,我的代码如下..

<?php session_start(); error_reporting(E_ALL^E_WARNING);?> 
<?php 
    //include("local_config.php"); 
    include("lib/config.php"); 
    include("nav_class.php"); 
    $obj=new navig(); 

    if(isset($_SESSION['user_id'])) 
    { 
    $user_id=$_SESSION['user_id']; 
    $pic="select Picture from Profile where user_id=$user_id "; 
    $pic_result=mysql_query($pic) or die ("sorry".$pic); 
    $count=mysql_num_fields($pic_result); 

    if($count==1) 
    { 

    $rows=mysql_fetch_row($pic_result); 

    $_SESSION['picture']=$rows[0]; 
    $profile_pic=$_SESSION['picture']; 

    $photo="profile/".$profile_pic; 
    } 
    else 
    { 
    $photo="profile/img.jpg"; 
    } 
    } 
    else 
    { 
    header("location:index.php?er=3"); 
    } 

    ?> 

    <div id="templatemo_header_wrapper"> 

<div id="templatemo_header"> 

    <div id="site_logo"></div> 


     <div id="menu_nav" > 
    <ul id="css3menu1" class="topmenu"> 
    <li class="topfirst"><a href="profile.php?apps=1" style="height:15px;line- 
    height:15px;">Dashboard</a></li> 
    <li class="topmenu"><a href="#" style="height:15px;line-height:15px;">Profile</a>  
     </li> 
    <li class="topmenu"><a href="#" style="height:15px;line-height:15px;">Settings</a> 
    </li> 
    <li class="toplast"><a href="#" style="height:15px;line-height:15px;">Prateek  

</ul> 
</div> </div><!-- end of header --> 
</div> 

    <div id="tempatemo_content_wrapper"> 

    <div id="templatemo_content" align="center"> 

    <div class="recent_projects"> 

      <div align="right"> 
      <table width="50%" border="0"> 
      <tr> 
      <td width="85%" height="20" style="border-right:1px solid #D0D0D0;"><div  
     align="right">Welcome&nbsp;&nbsp;&nbsp;<?php echo $_SESSION['fname']."&nbsp;". 
     $_SESSION['lname']; ?></div></td> 
      <td width="15%" > <div align="center"><a href="logout.php">Log Out</a></div> 
      </td> 
      </tr> 
      </table> 
      </div> 

    </div> 
    <!--end of recent project--> 
+0

是否有任何脚本的你包括使用标题()? – rws907

+0

可能的重复[警告:不能修改标题信息 - 标题已发送(PHP)](http://stackoverflow.com/questions/4173740/warning-cannot-modify-header-information-headers-already-sent-php) –

回答

1

丑陋的,丑陋的代码....

<?php 

@session_start(); 
error_reporting(E_ALL^E_WARNING); 

//include("local_config.php"); 
include('lib/config.php'); 
include('nav_class.php'); 

$obj = new navig(); 

if(!isset($_SESSION['user_id'])){ 

    if(!headers_sent()) 
    header('Location: index.php?er=3'); 
    echo '<script type="text/javascript">document.location.href="index.php?er=3";</script>'; 
    die(); 

} 

$photo = 'profile/img.jpg'; 

if(!isset($_SESSION['picture'])){ 

    $user_id = (int) $_SESSION['user_id']; 
    $pic = "SELECT Picture FROM Profile WHERE user_id=$user_id"; 

    if(($pic_result = mysql_query($pic)) && mysql_num_rows($pic_result)==1){ 
    $row = mysql_fetch_row($pic_result); 
    $_SESSION['picture'] = $row[0]; 
    $photo = 'profile/'.$row[0]; 
    } 

}else{ 

    $photo = 'profile/'.$_SESSION['picture']; 

} 

?> 

<div id="templatemo_header_wrapper"> 
    <div id="templatemo_header"> 
    <div id="site_logo"></div> 
    <div id="menu_nav"> 
     <ul id="css3menu1" class="topmenu"> 
     <li class="topfirst"><a href="profile.php?apps=1" style="height:15px;line-height:15px;">Dashboard</a></li> 
     <li class="topmenu"><a href="#" style="height:15px;line-height:15px;">Profile</a></li> 
     <li class="topmenu"><a href="#" style="height:15px;line-height:15px;">Settings</a></li> 
     <li class="toplast"><a href="#" style="height:15px;line-height:15px;">Prateek</li> 
     </ul> 
    </div> 
    </div><!-- end of header --> 
</div> 

<div id="tempatemo_content_wrapper"> 
    <div id="templatemo_content" align="center"> 
    <div class="recent_projects"> 
     <div align="right"> 
     <table width="50%" border="0"> 
      <tr> 
      <td width="85%" height="20" style="border-right:1px solid #D0D0D0;"><div align="right">Welcome&nbsp;&nbsp;&nbsp;<?php echo $_SESSION['fname'].'&nbsp;'.$_SESSION['lname']; ?></div></td> 
      <td width="15%" ><div align="center"><a href="logout.php">Log Out</a></div></td> 
      </tr> 
     </table> 
     </div> 
    </div> 
    <!--end of recent project--> 

... 
1

使用ob_start()在脚本的开始和ob_end_flush()末。

Reference

+2

导致性能下降..这里有什么需要? –

+0

@ArunKillu这是许多解决方案之一。无法修改标题问题可以很容易地搜索到,但我认为用户是决定快速解决方案还是优化解决方案的用户。我同意这一点。性能下降 - >让用户决定,然后逐行查看代码,找到之前输出的内容:) – swapnesh

+0

我刚才指出,因为..他会得到一个错误的图片,当他得到这个错误时,他肯定会使用这是不应该使用的。 –

0

我不建议隐藏警告你更好解决它 你可以使用这个隐藏警告...

error_reporting(E_ERROR | E_PARSE); 
+1

why -ve?请发表评论,以便我可以更好地回答我的答案。 –

0

你的代码包含错误。我看不到包含文件的内容,但是您发布的错误消息是,您尝试在会话已启动时开始会话。

寻找在你的代码session_start(),做之前不echo东西header()

0

不回应任何数据,直到您叫header()后,你会不会有这个问题。

0

您的nav_class.php正在输出119行的内容,并可能在此之后。

header("location:index.php?er=3"); 

有一些补救措施:

  • 请致电头之前不能输出任何东西
  • 包括nav_class.php和创建
  • 电话头之前,你对这个脚本的第32行调用头$obj (在你的头文件调用之前,你没有使用$obj
  • 正如swapnesh建议的那样,使用ob_start()ob_end_flush()

我喜欢前两种解决方案之一。

3

对于这个问题,许多解决方案!!!!

1)header()必须先天下之忧,如果标题是包含任何页面顶部的文件,然后包括它写在包含页头session_start .....

2)在开始使用ob_start()它将页面的输出存储在缓冲区中,然后同时输出每一样东西,最后也使用ob_end_flush() ...

3)记住要删除空的空间和回声陈述,如果刚过

 
    else 
    { 
     header("location:index.php?er=3"); 
    } 
    include("nav_class.php"); 
    $obj=new navig(); 

并在config.php确保没有回音声明任何头命令

4)之前将include("nav_class.php"); $obj=new navig();

eg echo“Database Connection Successful”;

删除评论以及

同时删除或死亡( “对不起” $ PIC);查询

0

不要echoprint_r()头负荷后,如果你真的要禁用所有的错误,然后检查index.php文件,如果你使用的是笨,那么你可以不设置所有错误消息.. 有没有选项并设置

if (defined('ENVIRONMENT')) 
{ 
    switch (ENVIRONMENT) 
    { 
     case 'development': 
      error_reporting(E_ALL); 
     break; 

     case 'testing': 
     case 'production': 
      error_reporting(0); 
     break; 

     default: 
      exit('The application environment is not set correctly.'); 
    } 
} 

只是检查你的php.ini,然后检查你要哪种类型的错误,并只设定一个参数,并在这个函数替换error_reporting(E_ALL);可以取代你的参数