0

Im making a script to create a tempoary text file to download and redirect back to a page,but im having the issue that everything after the header information is sent goes into the text file upon download.

<?php
session_start();
include('session.php');
//echo $login_session;
require_once "getconnected.php";
$connection = getConnected();

header('Content-Type: application/octetstream; name="file.txt"');
header('Content-Type: application/octet-stream; name="file.txt"');
header('Content-Disposition: attachment; filename="file.txt"');
?>
Hello, world.
<script>

window.location.href="/usercp/monitorproducts.php";

</script>
<?



?>

as you can see the javascript code goes into the text file due to the header.. what can i do?

thank you.

downrep_nation
  • 432
  • 1
  • 7
  • 16
  • possible duplicate of [PHP generate file for download then redirect](http://stackoverflow.com/questions/822707/php-generate-file-for-download-then-redirect) – showdev Feb 27 '15 at 19:37
  • I don't think it is possible to get more than one answer to a web request. Where DO you put the contents in your file.txt download? – Pianoman Feb 27 '15 at 19:37

2 Answers2

2

Once you use "header" to indicate that you are sending back a file, the client will treat it as such.

The web server is sending back a response header that is telling the browser it's about to receive a file.

MegaAppBear
  • 1,220
  • 1
  • 9
  • 11
0

wow i found a solution that works!

<?php
session_start();
include('session.php');
//echo $login_session;
require_once "getconnected.php";
$connection = getConnected();
header( "refresh:5;url=/usercp/monitorproducts.php" );
header('Content-Type: application/octetstream; name="file.txt"');
header('Content-Type: application/octet-stream; name="file.txt"');
header('Content-Disposition: attachment; filename="file.txt"');
?>
hello world

this redirects immoderately after downloading file,this worked randomly! the delay is nessecary

downrep_nation
  • 432
  • 1
  • 7
  • 16