Search the Community
Showing results for tags 'http headers'.
-
Hello everyone! I'm new to the forum, so let me start by saying I'm happy to be here and that I'm learning a lot from Larry's (awesome!) books and I'm thoroughly enjoying them. I'm having a problem with HTTP Headers, specifically the header() function. Script 11.5, entitled "show_image.php" in Chapter 11, doesn't seem to work for me. I have tried it on two separate computers (desktop with Windows XP Pro, and laptop with Windows 7 Home) both using Firefox 11.0 and XAMPP 1.7.4 (which uses PHP 5.3.5). So, then I tried to test out the simple headers, like the ones Larry uses on pages 356 & 357 and they, too, seem to not be working correctly for me. Presumably this means that I am probably doing something wrong and/or need to change some settings, perhaps in the php.ini file. Anyhow, when I run the following simple program, the header redirects my browser to the url indicated, despite the fact that I put all kinds of HTML stuff before it. Here's the program: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>This is my title</title> </head> <body> <h1>Welcome to my website !</h1> <p>Insert witty banter in this paragraph...</p> <hr /> <a href="http://www.bbc.co.uk/news/">BBC News</a> <?php echo "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; #### a header() function to redirect the browser to The New York Times homepage... header('Location: http://www.nytimes.com/'); ?> </body> </html> And then, when I run a similar program with three headers for the browser to receive a PDF, everything seems to open or download, but my PDF readers (I tried Foxit and Adobe) keep giving me the following error (even when I omit all of the HTML stuff before the headers) in a dialog box: format error: not a PDF or corrupted. Anyhow, here is the second program: <?php #### 3 header functions for a PDF of the train schedule... header("Content-Type:application/pdf\n"); #### and I tried putting this PDF, and other PDF's and image files in various folders... header("Content-Disposition:attachment; filename=\"C:/xampp/htdocs/NJTransit.pdf\"\n"); #### I find the length, in bytes, by right-click, properties, size and size on disk header("Content-Length: 622592\n"); ?> It's probably something wrong with me and/or my computers, but needless to say it's driving me crazy, and I believe that I need to use HTTP headers in Chapter 12, "Cookies and Sessions." I'm wondering, for example, why the first program appropriately redirects the browser despite all of the HTML junk before it, and why the second program informs me that it's not a PDF or that it's corrupted. As for the second problem, I've tried many different things in a futile attempt to fix these problems, such as: moving the PDF to different folders using different PDF's and images, in multiple folders putting in different sizes (right-click, properties, size and size on disk) for header("Content-Length: 622592\n") trying these programs and others on separate computers... Everyone here seems much better at PHP than me, and by including both programs, someone may notice a common source of my frustration. Any help would be really, really appreciated! Thanks again!
- 3 replies
-
- http headers
- header() function
-
(and 1 more)
Tagged with: