嗨,我需要一点帮助,我有如下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
首先
将location
更改为Location
,但其次确保删除在header()
函数之前发生的任何输出。这包括:
- 所有
echo
语句。 - PHP 标记(空格和制表符)之外的任何空格。
- 确保签入所有包含/必需的文件以及已创建实例的
WhatsProt
类的构造函数。
试试这个。在您的脚本中,位置关键字中的第一个字母"L"不是大写字母。
header('Location: index.php');