PHP header 重定向功能无效

PHP header redirect function not working

嗨,我需要一些帮助,我有如下 php 代码,当我尝试使用 header 重定向 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

试试这个。在您的脚本中,Location 关键字中的第一个字母"L" 不是大写。

    header('Location: index.php');

首先将 location 更改为 Location,但其次确保删除在 header() 函数之前发生的任何输出。这包括:

  1. 所有 echo 个语句。
  2. PHP 标签(空格和制表符)之外的任何空白。
  3. 确保签入所有 included/required 文件,并在 WhatsProt class 的构造函数中创建实例。