redirect after headers sent

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dstefani
Forum Contributor
Posts: 140
Joined: Sat Jan 11, 2003 9:34 am
Location: Meridian Idaho, USA

redirect after headers sent

Post by dstefani »

Hello,

Can I do anything to redirect after spawning the download dialog?

I have a file that uses these headers and offers a download:

Code: Select all

function stream_rtf_file($file_name, $file_text) {

    include "includes/rtf_class.php";

    // headers
    Header("Content-type: application/octet-stream");
    Header("Content-Disposition: attachment; filename=$file_name");

    // do it
    $rtf = new RTF("includes/rtf_config.inc");
    $rtf->parce_HTML($file_text);
    $fin = $rtf->get_rtf();
    echo $fin;


}
If this was a pop-up window, that would be fine, but i don't want to use a pop-up, how can I go anywhere after I do this?

Thanks,

dstefani
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

You can't redirect after the output was sent - not with PHP.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Use meta redirecting in your HTML. After a set time, it will refresh to another location.

Code: Select all

<html>
<head>
<meta http-equiv="refresh" content="5;url=http://www.mysite.com/index.php">
</head>
<body>
</body>
</html>
In this example, after 5 seconds, the page redirects to http://www.mysite.com/index.php.
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post by aerodromoi »

Another option would be a JavaScript redirect using:

Code: Select all

window.location="http://www.targetdomain.com/";
However, I'd always include a text link to that page since you never
know whether the user has JavaScript enabled or not.

aerodromoi
Post Reply