A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearRedirect to specified URL on PHP script completion? - page 1
User InfoPosts
Redirect to specified URL on PHP script completion?#1
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');
?>

posted date: 2008-12-09 10:50:00


Re: Redirect to specified URL on PHP script completion?#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-09 10:50:01


Re: Redirect to specified URL on PHP script completion?#3
If "SOMETHING DONE" doesn't invovle any output via echo/print/etc, then:<?php // SOMETHING DONE header('Location: http://www.momige.com');?>

posted date: 2008-12-09 11:02:00


Re: Redirect to specified URL on PHP script completion?#4
<?php// do something hereheader("Location: http://example.com/thankyou.php");?>

posted date: 2008-12-09 11:03:00


Re: Redirect to specified URL on PHP script completion?#5
<?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 bufferwhile (ob_get_status()) { ob_end_clean();}// no redirectheader( "Location: $url" );?>

posted date: 2008-12-09 11:05:00


Re: Redirect to specified URL on PHP script completion?#6
You beat me to it. It might be worth mentioning that, since headers can only be sent if no output has been generated, the whole page/application might need to be wrapped in an ob_start().

posted date: 2008-12-09 11:08:00


Re: Redirect to specified URL on PHP script completion?#7
Note that this will not work:header('Location: $url');You need to do this (for variable expansion):header("Location: $url");

posted date: 2008-12-09 11:40:00


Re: Redirect to specified URL on PHP script completion?#8
When I tried this, I received this error: "Warning: Cannot modify header information - headers already sent by (output started at example.php:1)" Do you know why this would be happening?

posted date: 2008-12-09 14:07:00


Re: Redirect to specified URL on PHP script completion?#9
This means you're outputting something before ob_start() or after the ob_end_clean() block. Output buffering (the ob_* functions) take care of buffering any output allowing you to use it or (as in this case) discard it later. Put your code at //do stuff here

posted date: 2008-12-09 14:27:00


Re: Redirect to specified URL on PHP script completion?#10
You could always just use the tag to refresh the page - or maybe just drop the necessary javascript into the page at the end that would cause the page to redirect. You could even throw that in an onload function, so once its finished, the page is redirected<?php echo $htmlHeader; while($stuff){ echo $stuff; } echo "<script>window.location = 'http://www.yourdomain.com'</script>";?>

posted date: 2008-12-09 20:44:00


Re: Redirect to specified URL on PHP script completion?#11
Why didn't I think of that! Thank you for thinking outside the box...

posted date: 2008-12-10 10:50:00


Re: Redirect to specified URL on PHP script completion?#12
Or, of course: header('Location: ' . $url);

posted date: 2009-01-26 21:31:00


select page: « 1 2 »
Copyright ©2008-2017 www.momige.com, all rights reserved.