Disable Printing Web Page PHP
how can i disable printing a webpage using PHP or Javascript??
any code??
my system will go like this:
the user can print the webpage (html) only once
and then when he/she will attempt to print again that page,
there will be an alert or message that he/she can't print anymore
(CTRL + P or using File> Print)
i have alreay one field in my database with the value 1 or 0.
If 1, he can no longer print.and if 0 he can print.
Now my problem is how can i disable printing? both using ctrl+p
or using the File Menu.
thanks in advance..
Related Article: Print a web page using php code
is a PHP discussion thread by sri. that has 3 replies, was last updated 6 months ago and has been tagged with the keywords: php.
newbie26
Junior Poster in Training
59 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
You can try to achieve this, but there are so many ways around this, that it is impossible to solve.
pritaeas
Posting Prodigy
9,533 posts since Jul 2006
Reputation Points: 1,194
Solved Threads: 1,494
Skill Endorsements: 98
try fooling around with, css
some code that chances the class of the body to "noprint" one with a style @media print{.noprint{display:none;}} remembered in a cookie or a value in the user table, easily bypassed but so is everything else,
I dunno, something like
crappydoodle
<?php
// database connection code etc
// some ajax to confirm active connection so it isnt being run locally
echo '<body class="';
if($setting<>"0") echo 'noprint ';
echo 'bodytext" onload="stuff">';
// some ajax to crate a print button and update $setting in the user table when it is clicked
?>
not complete code just thoughts
almostbob
Nearly a Senior Poster
3,303 posts since Jan 2009
Reputation Points: 585
Solved Threads: 403
Skill Endorsements: 7
how will i know if the user already printed?
is there any way that i can update my database table field
if the user printed a document??
in php code.
thanks..
newbie26
Junior Poster in Training
59 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
In most cases you won't know. You can add a print button on your page, and notify a PHP script if it gets clicked. However, if they use the browser's menu, you won't get a notification. Even if they use your button, they can always set the number of copies in the print dialog, you'll never know how much they printed.
pritaeas
Posting Prodigy
9,533 posts since Jul 2006
Reputation Points: 1,194
Solved Threads: 1,494
Skill Endorsements: 98
is there any other way to achieve want i want??
i was able to disable printing with ctrl + P
and what i did when the user uses file>print, there will be no
display when he/she prints.
now, is there a way that i can automatic print??so that the user
will not be able to type how many copies he.she wants to print?
i searched google with many suggestions to bypass print dialog box but they all
didn't work.
newbie26
Junior Poster in Training
59 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
As has been mentioned by each poster...there is no guarantee in this. Even if you disabled all of the browser's print functions they could technically copy/paste the page (granted there be no design elements) into a text file and print it from there.
And companies that make browsers do not want site developers to have control over a user's browser due to malicious intent that some might have. There are ways as suggested above to try to make it more difficult to print it out after a first time and then MAYBE it'd be too much work for someone to bother printing it again but if someone really wanted to, they could do it.
weekendrockstar
Junior Poster in Training
71 posts since Dec 2010
Reputation Points: 25
Solved Threads: 16
Skill Endorsements: 0