Solved

Printing to a specific port

Posted on 2003-12-01
13
270 Views
Last Modified: 2013-12-12
Does anyone know how to print text to a printer port?

Here is what I am trying to get out of the program.

<?php

$variable = "This is a test";

print $variable to lpt1:

?>

Thanks,

Jeremys
0
Comment
Question by:jmsloan
  • 7
  • 6
13 Comments
 
LVL 13

Expert Comment

by:lozloz
ID: 9854167
well here are the functions for using a printer in php on windows: http://www.php.net/manual/en/ref.printer.php

using printer_open (http://www.php.net/manual/en/function.printer-open.php), if for some reason you always want it on lpt1, i guess you should set it as default and just use the printer_open function without an argument

loz
0
 
LVL 3

Author Comment

by:jmsloan
ID: 9858194
Actually lpt1 is set up as a reciept printer, and I only want to browser to print to this device when they run this certain php script
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9858224
how do you mean? if you only want to print when a certain page is accessed then only use these functions on that page

loz
0
 
LVL 3

Author Comment

by:jmsloan
ID: 9858270
I currently have this code

<?php
$handle = printer_open("\\chnt5\pos2100");
$handle = printer_open();
printer_write($handle, "This is a test");
printer_close($handle);

?>

and it gives me a

Fatal error: Call to undefined function: printer_open()

error
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9858293
you need to add the line extension=php_printer.dll to your php.ini file and you need to be running windows on the server

loz
0
 
LVL 3

Author Comment

by:jmsloan
ID: 9858323
I have the php server running on linux.  I was wanting who ever accessed the web page (from windows machine) to be able to print from lpt1.  Is that possible?  
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 13

Expert Comment

by:lozloz
ID: 9858405
i don't know if we're trying to achieve the same thing here - are you wanting a printer attached to the server to print or for the user's printer to? you can't control the user's printer in php as it's a server-side language and this would be quite a big security issue.. you'd need to use javascript and have the user's agreement through a dialog box to print a page to their printer. if you're talking about a printer on the server machine, you need windows installed there. there might be a library to allow printing in linux but i haven't seen one personally

loz
0
 
LVL 3

Author Comment

by:jmsloan
ID: 9858452
I am talking about using the users printer to print the data.
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9858520
as i said, it'd be a huge security problem if you could create web pages which automatically printed from the user's printer.. have a look at this for using javascript to create a link allowing the users to print: http://developer.irt.org/script/49.htm

loz
0
 
LVL 3

Author Comment

by:jmsloan
ID: 9858613
What if I want to print a variable and not the window?  What is the security risk with web pages that automatically print to the users printer?
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9858863
hi,

well being able to control part of a user's computer from a webpage means people can just create scripts to loop printing over again, possibly cause errors in the printer and crash machines i suppose, other than it'd be a pest to have adverts that automatically printed, wasting your ink and paper

to print a var you'll need to modify this javascript:

http://developer.irt.org/script/1497.htm

loz
0
 
LVL 3

Author Comment

by:jmsloan
ID: 9858901
So are you saying it is possible to do it still.  The page I am creating is for a corporate intanet and will only be used by stores in our company.  So there will be no malicious code involved.  
0
 
LVL 13

Accepted Solution

by:
lozloz earned 25 total points
ID: 9859556
it's possible to have a link to print a page yes - it's just automatic printing which isn't possible. the best i can think of is having a javascript function which is executed when the page loads by using onload with the body tag

loz
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

911 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now