Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $msg = "Your first line "; // first line (20 chars max)
- $msg .= " "; // second line, comment this out if your display is one line only
- if(isset($_GET['firstLine'])) {
- $firstLine = $_GET['firstLine'];
- $len = strlen($firstLine);
- if($len > 20) {
- $firstLine = substr($firstLine, 0, 19);
- } else {
- str_pad($firstLine, 20);
- }
- $msg = $firstLine;
- if(isset($_GET['secondLine'])) {
- $secondLine = $_GET['secondLine'];
- $len = strlen($secondLine);
- if($len > 20) {
- $secondLine = substr($secondLine, 0, 19);
- }
- $msg .= $secondLine;
- }
- $msg = preg_replace("/[^A-Za-z0-9?![:space:]]/","",$msg); // strip any ASCII commands (eg newlines because they will break the command and print a page) use this if accepting user input.
- $msg = substr($msg,0,40); // (optional) truncate message to 40 characters (2 lines)
- $printerIP = '127.0.0.1'; // IPV4 (a.b.c.d) obviously change to your printer IP
- $socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
- socket_connect($socket,$printerIP,9100) or die("Could not connect to printer.");
- $data = chr(27) . "%-12345X@PJL JOB" . chr(13) . chr(10) .
- "@PJL RDYMSG DISPLAY=\"$msg\"" . chr(13) . chr(10) .
- "@PJL EOJ" . chr(13) . chr(10) .
- chr(27) . "%-12345X";
- socket_write($socket, $data) or die("Could not write to printer. Check connections.");
- echo "<strong>Printer status set to:<br>" . $firstLine . "<br>" . $secondLine . "</strong><br>";
- }
- ?>
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>Set HP Printer LCD Status</title>
- </head>
- <body>
- <form method="GET">
- <table>
- <tr>
- <td><label for="firstLine">First line (20 chars max):</label></td>
- <td><input type="text" id="firstLie" name="firstLine" size="20"></td>
- </tr>
- <tr>
- <td><label for="secondLine">Second line (20 chars max):</label></td>
- <td><input type="text" id="secondLie" name="secondLine" size="20"></td>
- </tr>
- <tr>
- <td></td>
- <td><input type="submit" value="Submit"></td>
- </tr>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement