打印类实现原理很简单就是用户点击打印时把数据保存到数据库,然后由js来调用打印机来打印,如果打印完了把记录删除,再执行一条打印了,具体代码如下。
类实现想法是:先把要打印的数据都收集起来,在用js调用window打印函数。目前就使用于IE。
类提供打印排队功能。(PS,说白了就是一条一条读取数据)
代码如下 | 复制代码 |
class Wprint{ //收集打印代码 private $data = array(); //处理打印代码 private $handle; public function __construct() { header("Content-type:text/html;charsetutf-8"); $this->link(); //链接数据库 $this->collect($_POST["username"],$_POST["content"],$_POST["ip"]); $this->handle(); } //链接数据库 private function link() { $link = mysql_connect('localhost', 'root', '123456'); mysql_select_db('shen', $link); mysql_query('SET NAMES utf8'); } //收集打印代码 private function collect($username,$content,$ip) { $code["username"] = $username; $code["content"] = $this->check($content); $code["ip"] = $ip; $code["state"] = 0; $code["priority"] = 0; array_push($this->data,$code);//数据节点入栈 } //处理打印代码入库 private function handle() { foreach($this->data as $value) { $sql = "insert into print(username,content,ip,state,priority) values('{$value["username"]}','{$value["content"]}', '{$value["ip"]}','{$value["state"]}','{$value["priority"]}')"; $query = mysql_query($sql); if($query) { $id = mysql_insert_id(); //获取最近insert操作得到的ID echo "数据收集成功,正在排队打印,排队ID为".$id; $this->num($id); } else { echo "数据收集失败,请3秒后再一次提交"; } } } //检查传人数据是否为空 private function check($string) { if(strlen($string) == 0 || $string == " ") { echo "数据收集失败,打印内容为空"; exit; }else { return $string; } } //获取打印排队人数 private function num($id) { $sql = "select id from print where state=0 and id $query = mysql_query($sql); $num = mysql_num_rows($query); echo ",您前面还有".$num."个人在排队"; } //打印数据 public function Yprint() { $sql = "select id,content from print where state=0 order by id asc limit 1"; $query = mysql_query($sql); $row = mysql_fetch_array($query); if(!empty($row["content"])) { echo ""; $id = $row["id"]; $sql = "update print set state=1 where id=".$id; mysql_query($sql); echo "打印处理完成"; }else { echo $row["content"]; } } } |
思想很简单,收集数据再一个一个处理。 这样就不仅解决了网络打印的问题,还避免了网络打印打印过程排队的问题

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Notepad++7.3.1
Easy-to-use and free code editor