-1

Warning: Cannot modify header information - headers already sent by (output started at /sms.php:9) in /sms.php on line 19

this happened when i use this code below.and i wanna redirect page to another page in my site

$username = '';
    $password = '';
    $client = new SoapClient('http://www.xxxx/xx');
    $numbers = 'xxxx ';
    $message = 
    'hi this is a test 
    !@#$%^&*
    ';
    $senderName = 'xxxxxx';
    try {
    $response = $client->sendSMS($username, $password, $numbers, $message, $senderName);
    var_dump($response);
    header('Location: http://www.yoursite.com/new_page.html');
    } catch(SoapFault $exception ) {
    echo $exception->faultcode . ' : ' .$exception->faultstring . PHP_EOL;
    }
hossam365
  • 11
  • 1
  • 1
  • 2
  • 1
    the header() function needs to be the first header set... Sooooo try and get it as high in your code as possible. I'll include in the – Shan Robertson Sep 06 '13 at 23:41
  • When all else fails you may consider `ob_start();` and `ob_end_flush();`. – StackSlave Sep 06 '13 at 23:44
  • `header('Location: http://www.yoursite.com/new_page.html');` this line is causing the error. Please check @relentless's link to be informed. – samayo Sep 07 '13 at 00:01
  • Any output, echo, var_dump, whitespace, anything before header will cause this. – Phix Sep 07 '13 at 00:13

1 Answers1

1

You're trying to print output with your var_dump($response); statement before using header(). Move your header() function before any output, or wrap your code in the output buffer using ob_start() and ob_end_flush()

http://php.net/manual/it/function.ob-start.php

http://www.php.net/manual/it/function.ob-end-flush.php

brazorf
  • 1,943
  • 2
  • 32
  • 52
  • ` sendSMS($username, $password, $numbers, $message, $senderName); header('Location: http://www.yoursite.com/new_page.html'); var_dump($response); } catch(SoapFault $exception ) { echo $exception->faultcode . ' : ' .$exception->faultstring . PHP_EOL; } ?> ` – hossam365 Sep 07 '13 at 03:24
  • Mate your code is not intelligible in this way. If u got the suggestions we gave, you should be able now to refactor your code so that every output statement (var_dump, print_r, print, echo, etc.) comes after any header() call – brazorf Sep 09 '13 at 17:19