Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Help with simple php page linking question

New Here ,
May 11, 2011 May 11, 2011

I posted this question yesterday but for some reason it isn't showing up on the forum, so I'm reposting.

I have a small php file to force a download when a user clicks on a link:

<?php

header ("Content-type:application/pdf");

header ("Content-Disposition:attachment;filename='form.pdf'");

readfile ("form.pdf");

?>

I need to add code to this script which will automatically redirect the user to the home page within the same browser window, either during or immediately after the file downloads. And if it is possible, prevent the browser back button from returning the user back to the page that contains the download link.

I tried adding this after the readfile line: echo "<a href="mywebsite.com/index.html" /a>";

But that failed miserably, a monument to my limited php skills. Can someone help me out?

TOPICS
Server side applications
552
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 11, 2011 May 11, 2011

Oops, my bad. My original message is now showing

on the board. Sorry about the double post. Now if I can just get someone to answer...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 12, 2011 May 12, 2011

You can do this in PHP:

header ("Location: redirectToHere.html");

Not sure how to disable the back button.

Nick

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 12, 2011 May 12, 2011

Hi Nick

Thanks for your suggestion!  I tried adding that header line, substituting the full path to index.html in place of redirectToHere. When I placed it after the readfile line in my script, the file downloaded normally but the browser page wasn't redirected. Then I tried putting your header line with the other header lines above readfile, but when clicking on the link, the file does not download and instead I get an error 404 Page not found. Am I missing something?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 12, 2011 May 12, 2011
LATEST

Hmm... when you call the readfile() it opens the file that you link to.  The location is then set to that, so you can't redirect.

Is there another way you could download the file?  I'm afraid I've gone slightly beyond my PHP knowledge.  Sorry.

Nick

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines