Jump to content
Larry Ullman's Book Forums

PhillyProgrammer

Members
  • Posts

    2
  • Joined

  • Last visited

PhillyProgrammer's Achievements

Newbie

Newbie (1/14)

  • Week One Done Rare
  • One Month Later Rare
  • One Year In Rare

Recent Badges

1

Reputation

  1. Thanks for your help Paul! So, a quick update: I figured out why my first script was not working exactly as I expected. After consulting the phpinfo() function, I turned off output_buffering (which was set to 4096 bytes). I'm not sure if I should turn it back on and increase the value from 4096, but at least now I know why the header was working despite all of the HTML and other stuff I purposely put before it. Hopefully, that does not affect me because my second script is still not working. It's still frustrating to have my PDF viewers unable to open the PDF, informing me that it's not a PDF or that it's corrupted.....
  2. 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!
×
×
  • Create New...