Solved

Printing to a specific port

Posted on 2003-12-01
13
277 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
[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
  • 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
WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

 
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
 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

617 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