Solved

How to use $SERVER['PHP_SELF'] and css to create printer friendly pages?

Posted on 2009-06-30
3
657 Views
Last Modified: 2012-05-07
I am trying to add a link in the header of my page that reads "Print" and allows the user to go to any page on the site and just click "Print" at the top of the page and it calls up a new style sheet that strips off the header, menu, and everything else and creates a printer friendly version of that page.  So I added <a href = '<?php echo $_SERVER['PHP_SELF']; ?>?print_me=yes'>Print</a></div>  to the header and an if statement that says if print_me=yes use print.css, else use main.css.

Everything works pretty well, but here is my problem.  When a user navigates to find something on the site the URL might look something like this http://www.jpeake.com/agteacher2/institution.php?sorter=institution&id=Williston+High+School .  When the user clicks "Print" on the header the print.css style sheet is called up, but the new page that loads is missing the ?sorter=institution&id=Williston+High+School part of the URL... so the url now reads http://www.jpeake.com/agteacher2/institution.php?print_me=yes and that doesn't do the user any good because now they can't print what they were trying to.

Any idea how to retain the string in the URL that comes after ? and append &print_me=yes to it?  I understand how to use  $_SERVER['PHP_SELF'] ,but I don't know how to make it get the entire url and string together.
<a href = '<?php echo $_SERVER['PHP_SELF']; ?>?print_me=yes'>Print</a></div>

Open in new window

0
Comment
Question by:jbpeake
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
Michael701 earned 500 total points
ID: 24750103
You don't have to have a separate css for print. use the built in media type.

http://www.w3schools.com/css/css_mediatypes.asp

0
 
LVL 2

Expert Comment

by:thinkingman2
ID: 24750956
Just define your stylesheets like so:
<link rel="stylesheet" media="screen" href="/screen-style.css" />
<link rel="stylesheet" media="print" href="/print-style.css" />
<link rel="stylesheet" media="all" href="/global-style.css" />

Open in new window

0
 
LVL 2

Expert Comment

by:thinkingman2
ID: 24750964
...and if you're wanting to strip out headers, etc, when printing, then add a little CSS magic to them, i.e.:
<div class="screenOnly headerDiv otherClassnames">
   This is my big chunky header with navigation and other stuff not to be seen while printing...
</div>
 
//and in your print.css stylesheet:
 
.screenOnly {
   display: none !Important;
}

Open in new window

0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question