0

Hie i need a littles help i have php code like below, when i try to use the header redirect php function it wont work as you can see below. The problem is with the last two lines of code

    <?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
Eman
  • 13
  • 1
  • 5
  • 1
    header is case sensitive, you need to utilize Location in place of location. capital L – ameenulla0007 Jan 23 '16 at 09:01
  • 3
    Possible duplicate of [How to fix "Headers already sent" error in PHP](http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) – Rajdeep Paul Jan 23 '16 at 09:03
  • There is some echo changing the header so the redirect won't work, You have to remove the echo, you can also redirect the output see: [ob_start](http://php.net/manual/en/function.ob-start.php) – LolWalid Jan 23 '16 at 09:11
  • Its not case sensitive but better to use capital letter . Must remove the white spaces – devpro Jan 23 '16 at 09:59

2 Answers2

0

First of all change location to Location, but secondly make sure you remove ANY output that happens before the header() function. This includes:

  1. All echo statements.
  2. Any whitespace outside of the PHP tags (spaces and tabs).
  3. Make sure you check in all included/required files and in the constructor of the WhatsProt class you have created an instance of.
HenryTK
  • 1,287
  • 8
  • 11
-1

Try this. In your script, The first letter"L" in Location keyword is not capital.

    header('Location: index.php');
Muhammad Umar
  • 349
  • 3
  • 14