How to redirect to another page in my site with PHP code?

16.6k views Asked by At

This is bulk SMS sending code, and it works good and sends messages, but after sending a message, the web browser redirects me to code in a white page.

I want after sending a message to redirect to another page on 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);
    } catch(SoapFault $exception ) {
    echo $exception->faultcode . ' : ' .$exception->faultstring . PHP_EOL;
    }
6

There are 6 answers

0
Tomasz Madeyski On

Use this code

header('Location: http://www.yoursite.com/new_page.html');

But remember that it won't work if there's any output already sent by php script. If so, you will get warning (check your error_reporting and display_errors in php.ini). So, in other words, you can't put it after var_dump because var_dump produces output. It might be also a good idea to put exit() after var_dump.

4
Jimmy Pelton On

You can redirect to a new page using header:

header('Location: http://www.yoursite.com/new_page.html');
0
Byndd IT On

you can use...

header('Location: your_url.php');

or you also use

?>
<script> window.location="your_url.php" </script>   
<?php 
0
Waruna Manjula On
----------
<?php
echo '<div style="text-align:center;padding-top:200px;">Go New Page</div>'; // Show Message
        $gourl='http://stackoverflow.com'; // goto url
        echo '<META HTTP-EQUIV="Refresh" Content="2; URL='.$gourl.'">'; //   Content= Redirect time (seconds)
        exit;

?>
----------
0
Asad Mukhtar On

Use this PHP code header ('location:http://www.google.com')

and this javascript code:

<script>
    window.location = 'http://www.google.com'   
</script>
0
Swap On
$username = '';
    $password = '';
    $client = new SoapClient('http://www.google.com/xx');
    $numbers = '8899';
    $message = 
    'hi check it
    !@#$%^&*
    ';
    $senderName = 'Winder';
    try {
    $response = $client->sendSMS($username, $password, $numbers, $message, $senderName)
    var_dump($response);
    } catch(SoapFault $exception ) {
    echo $exception->faultcode . ' : ' .$exception->faultstring . PHP_EOL;
    }