我需要一個小問題幫助我有像下面的php代碼,當我嘗試使用標題重定向php函數它不會工作,你可以看到下面。問題是與最後兩行代碼PHP頭重定向功能不工作
<?php
require_once __DIR__.'/../src/whatsprot.class.php';
$username = '11111111';
$password = '9lW8oEhIwuKtVPKouTffefee=';
$nickname = 'NUMBER';
$debug = true;
$w = new WhatsProt($username, $nickname, $debug);
$w->connect();
$w->loginWithPassword($password);
?>
<?php
$con=mysqli_connect("localhost", "user", "pass", "db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="SELECT number FROM testnumbers";
$result=mysqli_query($con,$sql);
// Associative array
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC))
{
$storeArray[] = $row['number'];
};
$arrlength = count($storeArray);
for($x = 0; $x <= $arrlength; $x++) {
//send picture
$w->sendMessageImage($storeArray[$x], 'demo/filepage1.jpg');
$w->pollMessage();
}
header('location: index.php'); //not working
exit(); //not working
頭區分大小寫,您需要利用位置代替位置。大寫L – ameenulla0007
[如何解決]可能的重複頭已經發送「PHP中的錯誤」(http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) –
有一些回聲改變標題,所以重定向將不起作用,你必須刪除回聲,你也可以重定向輸出見:[ob_start](http://php.net/manual/en/function.ob -start.php) – LolWalid