How to refresh previous page when download window is opened

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
renu
Forum Commoner
Posts: 30
Joined: Sat Nov 06, 2004 12:20 am

How to refresh previous page when download window is opened

Post by renu »

There is a download option(on submit) on my page which starts downloading some file.Downloading code is in another page.So i want to refresh the previous page when download option is clicked.
I dont know how to do this.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

Code: Select all

header('Location: http://somewhere.com/previous_page.php');
php_wiz_kid
Forum Contributor
Posts: 181
Joined: Tue Jun 24, 2003 7:33 pm

Post by php_wiz_kid »

You could use JavaScript:

Code: Select all

<form method=&quote;post&quote; action=&quote;somepage.php&quote; onsubmit=&quote;window.open('...');&quote;>
...
<input type=&quote;submit&quote; name=&quote;submit&quote; value=&quote;submit&quote; onclick=&quote;window.location='...';&quote; />
Or, with PHP.

Code: Select all

<?php
header("Location: ...");  //Redirects the page
?>
If you're redirecting in the middle of the PHP script. Like you're redirecting in an if-statment make sure to stop the script and then redirect.

Code: Select all

<?php
if(...) {
     die(header("Location: ...")); //Stops the script and then redirects.
} elseif(...) {
     ...
}
?>
Make sure that when you're using the header() function to not print anything onto the screen or have any whitespace between the <?php and ?> tags. You'll get an error saying headers already sent.
Post Reply