mPrinter
Unofficial forum about mPrinter.

Home » Using mPrinter » mPrinter web » Print through php from any website
Print through php from any website [message #87] Sun, 09 February 2014 21:26 Go to next message
yanikpei is currently offline  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 Smile
Re: Print through php from any website [message #88 is a reply to message #87] Tue, 11 February 2014 13:22 Go to previous messageGo to next message
badger is currently offline  badger
Messages: 71
Registered: September 2013
Location: Prague, CZ
Member
Administrator
Hi yanikpei,
can you please provide some example of whole page for us "php newbies"? For my "first steps" I'd like to have some working example that I can save as <something>.php to my http server and it will "do something" (I mean something meaningful, not printing the error Smile ).


Re: Print through php from any website [message #89 is a reply to message #88] Thu, 13 February 2014 19:08 Go to previous messageGo to next message
AnMartini is currently offline  AnMartini
Messages: 13
Registered: September 2013
Location: Bologna, Italy
Junior Member

Wonderful!
You did a great job! I tried it and it does work!
@Badger, if you copy yanikpei's code on a file like "print.php" you only have to put your username, password and the id of your mPrint on the right places, then add
?>

at the end of the code.
When you'll visit that page the mPrint you chose will be queued. The only problem in my opinion is that you can not send variables.


Andrea
Re: Print through php from any website [message #90 is a reply to message #89] Fri, 14 February 2014 10:09 Go to previous message
badger is currently offline  badger
Messages: 71
Registered: September 2013
Location: Prague, CZ
Member
Administrator
crap.. shame on me. Sad I didn't play with it enough long to find out, that I have a typo in the password. Smile

Definitely a good start, yanikpei, thanks.


Goto Forum:
  


Current Time: Mon Jul 24 12:29:00 CEST 2017

Total time taken to generate the page: 0.03161 seconds