This is a discussion on "[SOLVED] PHP Printer-Friendly Page" within the PHP Forum section. This forum, and the thread "[SOLVED] PHP Printer-Friendly Page are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
[SOLVED] PHP Printer-Friendly Page
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
[SOLVED] PHP Printer-Friendly Page
[This is a follow-up from a thread in the Javascript Forum]
Hello, I recently acquired web space on a server that supports php. Now I would like to use php to create a page that when accessed, outputs the contents of another page in a printer-friendly format. I have tried this with javascript on my old server (see thread). The idea is a page called print.php that would have a "?page=/index.htm" parameter. The ?page= would be specified in a link on any page that I would like to be "printable". Can anyone help me out with this. As I said, I am new to php. Thanks in advance, SWagner
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
|
|
|
|
||||
|
Re: PHP Printer-Friendly Page
This is the easiset thing you could imagine
On any page that you want to be printable place this where you style tags are
http://www.example.com/index.php?print=1 This will load the right css because the script is checking if print is set in the query string. Cheers, PS. Welcome to PHP
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
|||
|
Re: PHP Printer-Friendly Page
OK, looks good. But isn't there a way to just create a print.php page with a code similar to this:
Regards, SWagner
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
Last edited by Stuart; Oct 14th, 2007 at 01:34. |
|
||||
|
Re: PHP Printer-Friendly Page
How is that any different to loading the same page again with a different style sheet.
If you are outputting the contents of the body tag on the given page, it will still have all of the HTML in it. That code you have seems unnecessarily complex for such a simple task. You could just use PHP to wite the head of the document only if they havn't asked to print the page.
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
|||
|
Re: PHP Printer-Friendly Page
OK. I see that this is a lot easier than I always thought it was. I think I will stick with the first code you gave me. Just one thing: wouldn't it also work if the link is just
PS: Renaming all of my pages from .htm to .php
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
Last edited by Stuart; Oct 14th, 2007 at 01:45. |
|
||||
|
Re: PHP Printer-Friendly Page
If you change !empty to isset you should be able to use just print.
This is because, isset checks if the variable is just there. Whereas empty checks if the value of the variable is present. What server are you running on? you can do an apache handler which will treat .htm files as php.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
|||
|
Re: PHP Printer-Friendly Page
I am running on a Cornell University hosted server. Go there. My actual website is one directory further - here.
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
|
|
||||
|
Re: PHP Printer-Friendly Page
The =1 sets the value of $_GET['print'] to true, leaving it as print means it is empty and the check will fall through and won't write the style sheet that you need.
You could create a page with this function to change all of the filenames to .php Please back up your files
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
|||
|
Re: PHP Printer-Friendly Page
Where would I put this code. The index.htm file or a different one? Also, would this actually change the extension to .php permanently, or does it just make the browser believe that the extension is .php? I am a little skeptic about my navigation acting up, not linking to the right pages anymore, and giving me my error page a hundred times over and a hundred times again.
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
Last edited by Stuart; Oct 14th, 2007 at 02:43. |
|
||||
|
Re: PHP Printer-Friendly Page
In a file all by itself which you run in your browser.
call it whatever you like. The contents of the whole file would be
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
|||
|
Re: PHP Printer-Friendly Page
Quote:
PS: The php code is showing asterisks again. I think that happens if you have the same code twice in a thread.
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
|
|
||||
|
Re: PHP Printer-Friendly Page
The change would be permanent so if you have an issue with misplaces links you might want to go with Alex's suggestion.
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
||||
|
Re: PHP Printer-Friendly Page
Quote:
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
|||
|
Re: PHP Printer-Friendly Page
Yes, you're right Alex. It seems like a bug -- every time that a script/code appears more than once in the same thread, any whitespace is replaced by asterisks (except for the first time the script/code appears)...
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
Last edited by Stuart; Oct 14th, 2007 at 13:19. |
|
||||
|
Re: PHP Printer-Friendly Page
Assuming no one else has, I've PMed an Admin.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
|||
|
Re: PHP Printer-Friendly Page
I know that we've pretty much solved the problem, but I can't get over that there is not a simple way to create a print.php page that dynamically extracts all the contents of the page that is specified in the url:
Rakuli, you've tried to talk me out of this, but I am going to keep fighting a bit longer. Here is a code that I found by searching Google.
)Now, I tried this on my server, but every time, it gives me the error message (see code above). I do not know why. Any help would be great. Thanks, SWagner PS: Rakuli, I know what you told me, but I don't think I want to change all of my extensions to .php. This code is the sort of thing I originally had in mind... and I've set my sights firmly onto it.
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
Last edited by Stuart; Oct 14th, 2007 at 14:27. |
|
|||
|
Re: PHP Printer-Friendly Page
Hold on, I think I know what is wrong: register_globals is turned off on my server... OK, I fixed that. But now there is a new error:
|