How can I get a PHP function go to a specific website when it is done running?
For example:
<?php //SOMETHING DONE GOTO(http://example.com/thankyou.php); ?>
I would really like the following...
<?php //SOMETHING DONE GOTO($url); ?>
I want to do something like this:
<?php //SOMETHING DONE THAT SETS $url header('Location: $url'); ?>
Answer: Use the PHP header() Function You can simply use the PHP header() function to redirect a user to a different page. The PHP code in the following example will redirect the user from the page in which it is placed to the URL http://www.example.com/another-page.php . You can also specify relative URLs.
In PHP, when you want to redirect a user from one page to another page, you need to use the header() function. The header function allows you to send a raw HTTP location header, which performs the actual redirection as we discussed in the previous section.
The header function in PHP can be used to redirect the user from one page to another. It is an in-built function that sends raw HTTP header to the destination (client).
php // create a new cURL resource $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, "http://www.example.com/"); curl_setopt($ch, CURLOPT_HEADER, 0); // grab URL and pass it to the browser curl_exec($ch); // close cURL resource, and free up system resources curl_close($ch); ?>
<? ob_start(); // ensures anything dumped out will be caught // do stuff here $url = 'http://example.com/thankyou.php'; // this can be set based on whatever // clear out the output buffer while (ob_get_status()) { ob_end_clean(); } // no redirect header( "Location: $url" ); ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With