2012-09-03 45 views
-5

我目前遇到一個問題,不斷給我的錯誤問題標題。這裏是我的代碼,任何人都可以幫助我檢查什麼是錯的,以及如何解決它?非常感謝。警告:無法修改標題信息 - 在*****線上已經發送(在*****開始的輸出)的標題*****

以下部分是一個PHP文件的底部部分,包括「包頭」:

echo'<table>'; 
      while ($result = mysql_fetch_array($sql, MYSQL_ASSOC)){ 
       echo '<tr>'; 
       echo '<td style="width:142px">'; 
       echo $result['instrument_id']; 
       echo '</td>'; 
       echo '<td style="width:142px">'; 
       echo $result['instrument']; 
       echo '</td>'; 
       echo '<td style="width:142px">'; 
       echo $result['type']; 
       echo '<br>'; 
       echo $result['amount'].'&nbsp;shares'; 
       echo '</td>'; 
       echo '<td style="width:142px">'; 
       echo $result['opening_rate']; 
       echo '<br>'; 
       $fp = fopen ("http://finance.yahoo.com/d/quotes.csv?s='".$result['instrument']."'&f=nsb2b3p2ophg.csv","r"); 
        //this uses the fgetcsv function to store the quote info in the array $data 
        $data = fgetcsv ($fp, 1000, ","); 
        echo ($data[3]);//current rate 
       echo '</td>'; 
       echo '<td style="width:142px">'; 
       echo $result['opening_value']; 
       echo '<br>'; 
       $value = $data[3] * $result['amount']; 
       $currentvalue = number_format($value, 2, '.', ''); 
       echo $currentvalue;//current value 
       echo '</td>'; 
       echo '<td style="width:142px">'; 
       echo $result['open_time']; 
       echo '</td>'; 
       echo '<td style="width:142px">'; 
       if($data[3] == 0){ 
       echo '<input type="submit" name="close'.$result['instrument_id'].'" value="Close" disabled="disabled"/>';} 
       else{ 
       echo '<input type="submit" name="close'.$result['instrument_id'].'" value="Close"/>';} 
       echo '</td>'; 
       echo '</tr>'; 

       fclose ($fp); 

       $name = 'close'.$result['instrument_id']; 
       $close = isset($_POST[$name]); 
       if($close){ 

        $instrumentid = $result['instrument_id']; 
        $_SESSION['instrumentid'] = $instrumentid; 


        $instrument = $result['instrument']; 
        $_SESSION['instrument'] = $instrument; 

        $amount = $result['amount']; 
        $_SESSION['amount'] = $amount; 

        header("Location:order_sell.php"); 
       } 
      } 
      echo'</table>'; 

當我包括在上面,這是背景文件,僅包括html元素的文件時,它會給我喜歡的警告錯誤消息:無法修改標題信息... 這裏是包含文件的代碼:

<?php 
session_start(); 

    // checks if $_SESSION['userid'] exists 
    $areYouLoggedIn = isset($_SESSION['username']); 
?> 
<!DOCTYPE html> 
<html> 
<head> 

<style type="text/css"> 

/* background*/ 
body { background: url(images/background2.png) center center fixed no-repeat; 
webkit-background-size:cover; 
moz-bacground-size:cover; 
-o-background-size:cover; 
background-size:cover;} 

/* top menu layout*/ 
.Topmenu{ 
width:1000px; 
background: #00AEEF; 
border-radius: 3px 3px 3px 3px; 
} 

/* top menu cell layout*/ 
.Tabcells{ width:200px; 
text-align:center; 
} 

/* top menu cell text layout*/ 

/* top menu cell text layout*/ 
.Tabtexteffect 
{ text-decoration: none; 
color:white; 
font-family:Arial; 
font-size:15px; 
} 

.Tabtexteffect:hover 
{ 
text-decoration: none; 
color:white; 
font-family:Arial; 
font-size:20px; 
} 

.Paragraph {text-align:justify; 
text-justify:distributed-all-lines; 
text-align-last:justify; 
font-family:arial; 
font-size:12pt; 
width:1000px; 
} 

.Box { 
width:950px; 
text-align:left; 
background: -webkit-linear-gradient(90deg, #F0E68C, #FFFFE0) repeat scroll 0 0 transparent; 
background: -moz-linear-gradient(90deg, #F0E68C, #FFFFE0) repeat scroll 0 0 transparent; 
border: 1px solid #AAAAAA; 
border-radius: 10px 10px 10px 10px; 
box-shadow: 0 0 15px #AAAAAA; 
} 

.Box2 { 
    width: 200px; 
    text-align: left; 
    background: -webkit-linear-gradient(90deg, #FFFA8C, #FFFFE0) repeat scroll 0 0 transparent; 
    background: -moz-linear-gradient(90deg, #FFFA8C, #FFFFE0) repeat scroll 0 0 transparent; 
    border: 1px solid #AAAAAA; 
    border-radius: 10px 10px 10px 10px; 
    box-shadow: 0 0 15px #AAAAAA; 
} 


.Button { 
background: -moz-linear-gradient(90deg, #0459B7, #08ADFF) repeat scroll 0 0 transparent; 
background: -webkit-linear-gradient(90deg, #0459B7, #08ADFF) repeat scroll 0 0 transparent; 
border: 1px solid #093C75; 
border-radius: 3px 3px 3px 3px; 
box-shadow: 0 1px 0 #FFFFFF; 
color: #FFFFFF; 
cursor: pointer; 
font-family: Arial,sans-serif; 
font-size: 12px; 
font-weight: bold; 
margin-right: -16px; 
margin-top: 16px; 
padding: 5px 10px; 
text-decoration: none; 
text-shadow: 0 1px 1px #333333; 
text-transform: uppercase; 
} 




</style> 


</head> 
<body> 
<form action="HomePage.php" method="POST"> 
<div style="width:1000px; margin:0 auto; min-height:100%;"> 
<div> 
<a href="HomePage.php"><img style="width:25%;" src="images/Mock Apprentice.png" alt="Mock Apprentice"></img></a> 
<?php 
if($areYouLoggedIn==false){ 
    echo'<table cellpadding="0" align="right" style="position: absolute; left: 940px; top: 15px;">'; 
    echo'<tr>'; 
    echo'<td width="130" align="center"><font face="Arial" size="3"><a href="Login.php"><input type="button" class="Button" value="Sign In""/></a></font></td>'; 
    echo'<td width="1" bgcolor=black><BR></td>'; 
    echo'<td width="100" align="center"><font face="Arial" size="3"><a href="Registration.php"><input type="button" class="Button" value="Sign Up""/></a></font></td>'; 
    echo'</tr>'; 
    echo'</table>'; 
} 
if($areYouLoggedIn == true){ 
    echo'<table cellpadding="0" align="right" style="position: absolute; left: 950px; top: 40px;">'; 
    echo'<tr>'; 
    echo'<td width="130" align="center"><font face="Arial" size="4" color="#00AEFF">Welcome'; 
    echo'&nbsp'; 
    echo'<font color="#FFD700">'; 
    echo($_SESSION['username']); 
    echo'</font>'; 
    echo'</font></td>'; 
    echo'<td width="1" bgcolor=black><BR></td>'; 
    echo'<td width="100" align="center"><font face="Arial" size="4"><a style="text-decoration: none; color:#00AEFF;" href="Logout.php">Logout</a></font></td>'; 
    echo'</tr>'; 
    echo'<table>'; 
} 
?> 
<HR color="#00AEEF"> 
</div> 
<div> 
<table width="1020" height="30" class="Topmenu"> 
<tr> 
<td width="200" height="30" class="Tabcells"><a href="Intro.php" class="Tabtexteffect">Intro</a></td> 
<td width="200" class="Tabcells"><a href="HowToUse.php" class="Tabtexteffect">How to use</a></td> 
<td width="200" class="Tabcells"><a href="Elearning.php" class="Tabtexteffect">Education Center</a></td> 
<td width="200" class="Tabcells"><a href="ITQuotes.php" class="Tabtexteffect">Trading Platform</a></td> 
<td width="196" class="Tabcells"><a href="ContactUs.php" class="Tabtexteffect">Contact Us</a></td> 
</tr> 
</table> 
</div> 
</div> 
</form> 
</body> 
</html> 

謝謝你這麼這麼這麼多!

回答

9

嘗試

echo '<META HTTP-EQUIV="Refresh" Content="0; URL=order_sell.php">';  
exit; 
+0

+1 cool oldschool – philipp

+0

謝謝!你是我的英雄! – user1616230

+0

@ user1616230然後選擇此作爲答案。 :) – Shekhar

0

在PHP header函數必須在之前調用任何輸出從服務器發送。這包括echo調用以及<?php ?>塊之前的HTML信息。

+0

更換header("Location:order_sell.php");謝謝。有沒有其他函數可以用來替換「標題」函數,以便我可以擺脫錯誤? – user1616230

+1

@ user1616230:這不是PHP header()函數的問題,而是HTTP協議的一個屬性:頭文件首先放置。 –

0

您不能發送header之後的文字已經被髮送到瀏覽器:

header("Location:order_sell.php"); 

需要的任何文/輸出之前/空白髮送/ echo'ed到瀏覽器。

2

無論您輸出什麼 - 僅HTML或PHP輸出:除非您使用ob_*()功能做一些欺騙,否則在輸出任何內容時您將無法發送標頭。

這就是它們被稱爲headers的原因:在HTTP協議中,它們位於每一個有效載荷體的前面 - 包括諸如<?php標記之前的空行之類的空白。

來解決,這將是重新集結你的邏輯,以第一計算一下頭文件中所需要的典型方式,然後創建你的輸出,通過echo()printf()include()或什麼的。

0

使用header(「Location:someLocation」)時,請確保沒有任何字符輸出到瀏覽器,否則會出現無法修改標題信息的錯誤。更多關於這個在:http://php.net/manual/en/function.header.php

相關問題