Solved

Printing to a specific port

Posted on 2003-12-01
13
268 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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.
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 …

747 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

10 Experts available now in Live!

Get 1:1 Help Now