PHP redirect to a page with Data
Ok so i have a from that people are using on our site to dow开发者_如何学编程nload a software application....There are actually 4 different forms that are linking to the same php script and i need to redirect all of them to the thank_you page with the $_POST['application_to_download'] the problem i am having is how do i send this variable with the php header..here is my code
this will just open the download
header("location:".$_POST['application_to_download']);
which works great but i need the user to be redirected to the thank_you page...so my second approach was to try the post approach
$post_data = "software={$_POST['application_to_download']}";
$content_length = strlen($post_data);
header('POST /downloads/thank_you HTTP/1.1');
header('Host: localhost');
header('Connection: close');
header('Content-type: application/x-www-form-urlencoded');
header('Content-length: ' . $content_length);
header('');
header($post_data);
Im not sure whats going on with this approach but its just not redirecting at all and lastly i can do this
header("location:"./downloads/thank_you?software=$_POST['application_to_download']);
something like that but the url looks like this
http://somesite.com/downloads/thank_you?software=videovision10_1_07.exe
which is not the prettiest if you ask me....i mean i know i can do this but i was looking for an alternative....btw here is why i need it on the thank_you page
<title>Thank You</title>
</head>
<body onload="window.location = '<?php print $_POST['software']; ?>'">
any suggestions
I would recommend instead that you redirect to the thank-you page, and use a meta-refresh to trigger the file download.
header('Location: /thank_you_page.php?redirectTo=' . $_POST['app_to_dl']);
and in the thank you page:
echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"1;URL=" . $_GET['redirectTo'] . "\">";
Give that a shot..
edit: Now I see you mentioned the GET variable... Do you really think people are looking at your URL and judging it?
For every request that a browser makes, you have one response that you can make. You want to display a thank you page. So that uses up the one. That means that the Thank You page has to automatically trigger the browser to make a second request.
Your options are a Javascript refresh:
window.onload = function() {
location.href = '<?php echo $app; ?>';
}
Or a HTTP Meta refresh (this one shows you how to wait 1 second):
<meta http-equiv="refresh" content="1;<?php echo $app; ?>">
For that page to know what $app
is, and embed it into the page, you have two options:
URL (GET) - which you have the code for (and say is ugly)
Session
session_start(); $_SESSION['app'] = $_POST['application_to_download'];
...
$app = $_SESSION['app']; unset($_SESSION['app']);
精彩评论