-5

我目前遇到的问题一直给我问题标题的错误。这是我的代码,谁能帮我检查一下有什么问题以及如何解决?非常感谢。

以下部分是包含“Header”的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>

非常感谢你!

4

5 回答 5

10

Try replacing header("Location:order_sell.php"); with

echo '<META HTTP-EQUIV="Refresh" Content="0; URL=order_sell.php">';    
exit;
于 2012-09-03T22:28:15.100 回答
2

Whatever you output - being HTML only or output from PHP: Unless you do some tricking with the ob_*() functions you lose the ability to send headers the moment you output anything.

This is why they are called headers: In the HTTP protocol they preceed every single piece of payload body - including whitespace such as empty lines before a <?php tag.

The typical way to tackle this would be to regroup your logic as to first calculate what headers you need, then create your output, via echo(), printf(), include() or whatever.

于 2012-09-03T22:21:52.360 回答
0

In PHP header functions must be called before any output is sent from the server. This includes echo calls as well as HTML info before the <?php ?> block.

于 2012-09-03T22:19:15.077 回答
0

You can't send a header after any text has been sent to the browser:

header("Location:order_sell.php");

Needs to be before ANY text/output/whitespace is sent/echo'ed to the browser.

于 2012-09-03T22:19:25.920 回答
0

When using header("Location:someLocation") be sure that you don't have any character outputted to the browser, otherwise you'll get the error Cannot modify header information. More on this at: http://php.net/manual/en/function.header.php

于 2012-09-03T22:22:31.933 回答