首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >忽略PHP警告

问忽略PHP警告
EN

Stack Overflow用户
提问于 2012-11-07 14:08:33
回答 7查看 957关注 0票数 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

我能做什么?,我的代码如下..

代码语言:javascript
复制
 <?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-->  
EN

回答 7

Stack Overflow用户

回答已采纳

发布于 2012-11-07 14:22:36

丑陋的代码...

代码语言:javascript
复制
<?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
EN

Stack Overflow用户

发布于 2012-11-07 14:10:20

在脚本开头使用ob_start(),在脚本末尾使用ob_end_flush()。

Reference

票数 1
EN

Stack Overflow用户

发布于 2012-11-07 14:10:54

我不建议隐藏警告最好是你修复它,你可以用这个来隐藏警告…

代码语言:javascript
复制
error_reporting(E_ERROR | E_PARSE);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13264062

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档