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
Solved

Printing to a specific port

Posted on 2003-12-01
13
272 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
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…

809 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