Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8757727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:22:22+00:00 2026-06-13T14:22:22+00:00

Possible Duplicate: Header Location + Content Disposition I have a page that generates excel

  • 0

Possible Duplicate:
Header Location + Content Disposition

I have a page that generates excel report using header content-type and save the generation information on the database (e.g. who generated the report,when etc.) My problem is why I can’t redirect the page. below is the sample code/algo

// excel content
/* excel content populates here */

// output to excel file
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=".$positionFileName);
header("Cache-Control: max-age=0");

// save logs on the database  
/* save logs code executed here */

// redirect page to get the logs on the database that display on the web page
header("location: report.php");  *<--- I can't redirect to report.php*

Here is exactly what I want

the user will do is to select type of report then click button generate to output the excel report (open/save dialog). then after that, the system will going to save the logs of generated report on the database then show it on the page. that’s why I want to redirect it again on report.php so that the logs will be get again on the database to display on browser.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:22:23+00:00Added an answer on June 13, 2026 at 2:22 pm

    The headers are colliding. First you say “here comes a document”, using Content-Disposition: attachment, and then you say “Oh no, it’s not coming, do an additional request to XYZ”, using the Location header. You can omit the Content- headers to achieve the same result.

    This however works for me:

    header("Content-Type: application/octet-stream");
    header("Content-Disposition: attachment; filename=foo.dat");
    header("location: foo.dat");
    

    In that I get redirected to the foo.dat file, which is displayed in the browser (so the Content-headers are ignored, since after the Location-header a new request is issued which does not get the Content-headers in its response. If you want to enforce attachment, either configure your web server to emit those headers for certain extensions or directories, or use fpassthru($filename) without the Location-header to directly emit the file without running into memory errors:

    header("Content-Type: application/vnd.ms-excel");
    header("Content-Disposition: attachment; filename=".$positionFileName);
    header("Cache-Control: max-age=0");
    
    // save logs on the database  
    /* save logs code executed here */
    
    fpasstrhu($positionFileName);
    

    But please note that any output generated during the executing of the code after the first three header()statements will be outputted to the browser, which’ll think it is file data.

    I guess this is currently also happening, causing the header("location: ...") to fail. Enable error reporting to see why and where there was data printed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Parse XML with Namespace using SimpleXML PHP SimpleXML Namespace Problem <?php header(Content-Type:
Possible Duplicate: format xml string I'm generating an XML page like so: header('Content-Type: text/html');
Possible Duplicate: get image from base64 string I tried header('Content-Type: image/png'); echo base64_decode($data);` But
Possible Duplicate: mail() header problem for html email I'm using the following for $headers
Possible Duplicate: Why does this integer division yield 0? I have a C header
Possible Duplicate: In C++ why have header files and cpp files? Coming from a
Possible Duplicate: C program without header I have been studying C for a long
Possible Duplicate: In C++ why have header files and cpp files? I was reading
Possible Duplicate: Declaring a function that return a 2D array in a header file?
Possible Duplicate: Can I have multiple background images using CSS? Is it possible to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.