Print through php from any website [message #87] |
Sun, 09 February 2014 21:26  |
yanikpei
Messages: 3 Registered: November 2013
|
Junior Member |
|
|
Hey guys,
I spent my whole weekend on printing any mPrint to my mPrinter from my web-project. I wrote a small script (PHP) and I included it into my project where I have to print receipts. You just need the id of an mPrint and your username and password.
Here is my script:
<?php
$tmp_fname = tempnam("/tmp", "COOKIE");
$curl_handle = curl_init ("http://manage.themprinter.com/login");
curl_setopt ($curl_handle, CURLOPT_COOKIEJAR, $tmp_fname);
curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, true);
$post_array = array('username' => 'YOUR_USERNAME', 'password' => 'YOUR_PASSWORD');
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $post_array);
$output = curl_exec ($curl_handle);
$curl_handle = curl_init ("http://manage.themprinter.com/queue/add");
curl_setopt ($curl_handle, CURLOPT_COOKIEFILE, $tmp_fname);
curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, true);
$mPrint_ID = 'YOUR_MPRINT_ID';
$params = 'id='.$mPrint_ID;
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $params);
$output .= curl_exec ($curl_handle);
$info = curl_getinfo($curl_handle);
echo $output.'<br><br>'.print_r($info,true);
Maybe someone finds this helpful..
Sorry for my english but I'm from Germany
|
|
|
|
|
|