Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect to specified URL on PHP script completion?

Tags:

url

php

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');   ?> 
like image 868
JoshFinnie Avatar asked Dec 09 '08 18:12

JoshFinnie


People also ask

How can I redirect a URL to another URL in PHP?

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.

How can I redirect a user to another page using PHP write code?

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.

How a page is redirected in PHP?

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).

How do I hit a link in PHP?

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); ?>


1 Answers

<? 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" ); ?> 
like image 152
Patrick Hogan Avatar answered Sep 26 '22 21:09

Patrick Hogan