2016-01-23 150 views
0

我需要一個小問題幫助我有像下面的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 
+1

頭區分大小寫,您需要利用位置代替位置。大寫L – ameenulla0007

+3

[如何解決]可能的重複頭已經發送「PHP中的錯誤」(http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) –

+0

有一些回聲改變標題,所以重定向將不起作用,你必須刪除回聲,你也可以重定向輸出見:[ob_start](http://php.net/manual/en/function.ob -start.php) – LolWalid

回答

0

所有變化locationLocation的第一,但其次要確保在刪除header()功能之前發生的任何輸出。這包括:

  1. 全部echo聲明。
  2. PHP標記(空格和製表符)以外的任何空格。
  3. 確保您檢入所有包含的/必需的文件以及您創建實例的WhatsProt類的構造函數。
+0

謝謝這工作 – Eman

-1

試試這個。在您的腳本中,位置關鍵字中的第一個字母「L」不是大寫。

header('Location: index.php'); 
+0

是否有任何類型的錯誤信息?像「標題已發送」 –