urden Posted August 9, 2006 Share Posted August 9, 2006 Hi, First time poster, long time lurker.I have a failry simple problem I'd really like to get solved. I'm hoping some header magic will do the trick, but let's see shall we. what the problem is:I'd like to serve a download from my own server with a PHP script, and then immediatly redirect to another website. The basic problem here is that I do not have any control of the final "landing" page that the user goes to, so I cannot serve the download from there (then it would all just be a simple matter of doing a header(Location:) and then have the landing page serve the download)obviously multiple header redirects won't work, as PHP just takes the last redirect instruction and executes that (that's the behavior I've seen anyway) - But this would be the optimum behavior:[code]case 2: //serve file and then redirect (fileurl and offurl) header("Location: $fileurl"); header("Location: $offurl"); break;[/code]I hope this is clear enough and that any of you guys have an idea on how to accomplish this...Thanks! :) Quote Link to comment Share on other sites More sharing options...
Chetan Posted August 9, 2006 Share Posted August 9, 2006 You cant do it with PHP but you canput javascript so that when one clicks to download it takes to the page and a popup downloads Quote Link to comment Share on other sites More sharing options...
urden Posted August 9, 2006 Author Share Posted August 9, 2006 Ahaaa, so you would put a script in the anchor tag which simply pops up the download PHP script and then redirects the user.That's an acceptable solution (maybe) ... I'll have to mull it over for a bit. The only "obstacle" I see is that it wouldn't be very pretty in conjunction with all the code I have so far (meaning, I'd have to update two pages instead of just one to fit in the javascript when adding a new download - The way I have constructed things anyway)I was hoping there was some way you could use the headers to accomplish this, or some exotic PHP approach. Oh well... If anybody has some other ideas let me know :) Quote Link to comment Share on other sites More sharing options...
urden Posted August 9, 2006 Author Share Posted August 9, 2006 Alrighty, I got it solved with the javascript approach. I wont post all the code here, just the stuff that took me the longest to get right. There is of course some form code and the underlying php which deals with everything, but I think you would be able to reverse engineer that fairly easily.this is the Javascript that pops the download script (and tells it that it is being popped so it knows just to serve the file) and then it submits the form to the download script as usual (which then makes the same download script redirect instead of serving the file)[code]function popsubmit(formelement,locelement){//first read vars and pop windowlocid = document.getElementById(locelement).value;vindue=window.open('inc/downloadn.php?locid='+locid+'&popped=yes','newwindow','width=400,height=300,top=100,left=100');document.forms[formelement].submit();}[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.