PHP cannot print to network printer - php

I have a server with ip 192.168.0.1, then I have a computer with ip 192.168.0.3 which access the server. I have a printer EPSON TM-U220 connected to 192.168.0.3, then I tried to print from the server to the printer using php command
copy($file, '//192.168.0.3/printername');
but it doesn't work, then I tried another function:
exec("print /d:\\\\192.168.0.3\\printername $file");
exec("copy $file \\\\192.168.0.3\\printername");
It says "unable to initialize device \\192.168.0.3\printername".
My computer and server run on windows7.
I already shared the printer to my server, I can test print page from the server.
how do I print to my network printer using PHP?
Thanks

After going some researches, I found a solution to my problem.
Run services.msc then double click Appache Service. At tab Log On, choose This account, then fill in the credential of the server.
After that, restart your appache..
My problem is solved after doing this..

Following erkape#s solution, I got auto printing for Laravel with Crystal Reports XI right:
$printname="\\\\SERVERBEKASI\\Canon iP2700 series (Copy 3)";
$driver='"winspool"';
$port='"Ne07:"';
$creport->SelectPrinter("winspool",$printname,$port);
$creport->PrintOut(fal`enter code here`se,1);
The solution on my system (Windows 7) looks like this:
create a new account as the administrator, set a password
Run services.msc, double-click Apache Service. At tab Log On, choose your new account, then fill in the credential of the server.
Restart Apache. Done

Related

xampp not working, just installed

I just downloaded xampp from "https://www.apachefriends.org/index.html" this link, and switched off my defender as it asked me to, after instaling, i ran it and switched on mysql and clicked admin on the gui but i get this " The web page is not available ", even though mysql is stil higlighited green in the ui, i even tried localhost:3306 as my port is 3306 and my pid is 4584, but still got " the web page not available" am i doing anything wrong here?
Check your server error logs under <XAMPP_INSTALLATION_PATH>/apache/logs/ directory. It will guide you if any port is already occupied.
I agree with #ErasmoOliveira as most of the time I faced similar thing & exiting skype fixed this issue.
run your XAMPP, then click Setup (Apache line), click on Apache (httpd.conf). in this file find the line Listen 80, change 80 with another port, example: type 81 or 8080 or whatever you want but that it respects the format /^[8]{1}[\d]{1, 3}$/
restart apache again, you will surely work correctly by tapping to your browser http://localhost:81 (if you replaced the port to 81)

Trying to run PHP script with wamp server

I’ve just installed WAMP server from http://www.wampserver.com/
And I’m trying to run my first PHP script (hello.php).
This is the code:
<!DOCTYPE html>
<html>
<body>
<?php
echo "My first PHP script!";
?>
</body>
</html>
When I drag hello.php into google chrome, I get a blank screen on the browser.
When I copy the file into C:\wamp\www and type http://localhost/hello.php into chrome, I get:
This webpage is not available
Google Chrome's connection attempt to localhost was rejected. The
website may be down, or your network may not be properly configured.
Error code: ERR_CONNECTION_REFUSED
Any help is much appreciated.
Thanks.
Edit: The icon in my system tray is yellow (indicating something is wrong maybe?)
Are you using Skype? A common problem when trying to develop locally is, that Skype is blocking Port 80. See this question for further information: Why Skype using HTTP or HTTPS ports 80 and 443?
When your your wampserver icon in the system tray shows yellow, it means some services have not started. In this case, it's most likely the apache service that was not started (might be dues to a conflict).
Check for the following
Is skype running? Exit skype and restart wampserver again
Is IIS installed on your machine? Easiest solution is to change the port of your apache from port 80 to say 8080. (do this via the httpd.conf file). Then try opening http://localhost:8080/hello.php
1st ensure that your wamp icon is green(its mean wamp is ready for use) for this purpose you should put your code into php file make helloworld.php file and put in wamp www folder and run with wamp server.
for hello world program in php just follow this tutorial
but before that you should have wamp server or xamp server on your pc(wamp/xmap are open source software's and it can easily get from google)
your 1st php program code:-
<?php
echo "hello world";
?>
output:-
hello world
for more Helping Step by Step Tutorial video:https://www.youtube.com/watch?v=7qtqzhdEX-c
after this tutorial you can able to move other intermediate level programs of php.

What is localhost path for accessing server file in android??

I want to send variable from android application to wamp server and retrieve data from server. Please suggest me and what is path of localhost for wamp server. I am using "localhost/TestAndroid/check.php". The error is occurred data is not parsed.
Please suggest me with code. How to accessing data from android application(JSON+Android+HTTPClient)?.
Thanks
Nitin
Use this localhost address in your code '10.0.2.2/TestAndroid/check.php'
For more Help:
http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/
Find the below link, it may help full
WAMP server
Follow these steps.
Make sure your PC and Phone are in the same network (Connected to the same wi-fi)
Open a command prompt and run ipconfig and get the IP adress. 99% chances are it'll be something like 192.168.X.X
Use this IP instead of localhost. i.e. 192.168.X.X/TestAndroid/check.php

Print to Zebra printer in php

Looking for the proper code to print from php web page to a zebra IP printer using RAW port 9100. Does anyone know if this is possible? I need to send a string in ZPL formatted output direct to ZM400 label printer. I've searched high and low, the closest I've found is this: Print directly to network printer using php
It seems very close to what I need, but when my php page hits that code, it doesn't do anything. Here's the code I used:
<?php
$handle = printer_open('\\\\192.168.2.206:9100\\');
printer_set_option($handle, PRINTER_MODE, "RAW");
printer_write($handle, "TEXT To print");
printer_close($handle);
?>
I realise this question is a little old but I recently had to perform this exact task and here is how I did it.
Main server is a Cloud-Based PHP server which is not on the local network. On the local network we have another machine which is simply running WAMP and this script, the Zebra printer itself is also on the local network at IP 192.168.1.201:
<?php
/*
* File Allows printing from web interface, simply connects to the Zebra Printer and then pumps data
* into it which gets printed out.
*/
$print_data = $_POST['zpl_data'];
// Open a telnet connection to the printer, then push all the data into it.
try
{
$fp=pfsockopen("192.168.1.201",9100);
fputs($fp,$print_data);
fclose($fp);
echo 'Successfully Printed';
}
catch (Exception $e)
{
echo 'Caught exception: ', $e->getMessage(), "\n";
}
Then, on the webpage generated by the cloud server we have some code which simply does an Ajax POST to the server on the local network, posting in the zpl_data to be printed.
Edit 2017
We've now moved things over to run through PrintNode (https://www.printnode.com/). We've found it to be really good so far, and allows us to print all kinds of documents without needing to use our own proxies, and also provide a whitelabelled installer so it looks like our own product. I'm not affiliated with PrintNode.
If you're looking to send ZPL to the printer, you don't necessarily need a dedicated printing library. You just need to open up a socket to that printer and send your ZPL directly. This is more of a general PHP socket-communication question as opposed to a printer-specific question.
If the server hosting your web app and the printers are on the same network, then you will be able to open the socket and send the ZPL. If, however, your printers and web app server are on different networks, you will not be able to print over sockets, on that model printer, without additional browser plugins or add-ons. Generally speaking, accessing a remote printer (or any device) via a web-site is a security risk.
The printer_open() and related functions are not part of the standard PHP language; they are part of an extension.
If you want to use them, you'll need to install the extension: See here for info on the printer extension.
However, please note that this extension is only available for PHP running on Windows.
If your server is not Windows, you will need to use an external program to send data to the printer. An example might look like this:
exec("lpr -P 'printer' -r 'filename.txt');
This info, and more can be found elsewhere on SO -- eg here: printing over network from PHP app
Hope that helps.
After hours of searchings I get the solutions :
After you install the printer on the needed IP:
exec('lp -d printer file');
In my case the command was:
exec('lp -d Epson-Cofetarie /home/clara/Desktop/txt.txt');
Where: printer = Epson-Cofetarie
file = /home/clara/Desktop/txt.txt
file need Apsolute path
I hope, this simple code will resolve the problem,
Put your ZPL code in a file e.g "barcode.zpl"
Share your Zebra Printer, so that it can be accessed In Windows Explorer by typing
e.g "\192.168.1.113[YOUR PRINTER NAME]";
Create PHP File, and write code:
<?php
$file="barcode.zpl";
copy($file, "//192.168.1.113/ZDesigner GK420t");
?>
Thank You

http://localhost/ not working on Windows 7. What's the problem?

I have a big problem opening http://localhost/ on Windows 7 (beta). I installed this os and everything went great; when I installed Wamp I saw that localhost is not working at all. I just see this error:
Failed to Connect
Firefox can't establish a connection to the server at localhost.
in Mozilla and Explorer.
I removed Wamp and after some weeks (that means two weeks from today) I installed NetBeans on Windows 7. I created a test PHP script and when I debug it, I get the same error again. I tried to access it with ip 127.... but still the same. What is the problem?
When i installed NetBeans I installed it in port 8080.
If you installed it on port 8080, you need to access it on port 8080:
http://localhost:8080 or http://127.0.0.1:8080
To fix the port 80 problem do:
From cmd as administrator:
sc config http start= demand (you need a space after the equal sign and not before)
Reboot
Run the command (netsh http show servicestate) as administrator to check that the port 80 is in use
After you have run this command, you can disable http.sys as follows:
net stop http (stop the process)
Sc config http start= disabled (if you want to disable the service forever)
it works for me.
Edit your C:\Windows\System32\drivers\etc\hosts file
Make sure there is an entry that looks like this:
127.0.0.1 localhost
If there is an entry like
:: localhost
Comment it out to look like this
\#:: localhost
This should fix your problem, I've had this problem in the past.
For me, it was skype causing the problem. Once I stopped skype, everything worked. I have 1.7.1 xampp (mysql and apache) running on Windows 7 x64.
It sounds like you have no web server running at all anywhere.
Have you tried enabling IIS and using it to display a basic html file first?
Programs & Features -> Turn Windows Features On/Off -> Internet Information Servcies
Then, place your html file in C:\inetpub\wwwroot\index.html and browse to http://localhost.
Once this works, try to get WAMP/php working. Be careful of port conflicts.
My initial thought is that you are missing an entry in the hosts file. Something like "127.0.0.1 localhost", however, you mention that you are getting a 404 error. That means that the webserver is connecting to your client/browser and responding to the request for a particular webpage.
I'm not familiar enough with Windows 7, however, I'm pretty sure that it does not include a webserver by default. Also, unless you actually code, build and run a webserver application using netbeans you're not going to get the desired response.
When it comes down to it.... your issue is going to be one of the following:
1) you're serving static documents and the webserver is not configured to serve the files from whatever the proper DOCROOT should be. This includes PUBLIC folders in the user's directories. (the basic apache install include a basic homepage)
2) you have a dynamic webserver application where the controller is looking at the application path in order to decide what page to display or what function to execute. (see MVC - Controller). Basically incomplete implementation.
3) yet another configuration error: your website might actually define a virtual domain. (something other than localhost) so when you look for localhost in the URL the server might not be configured to provide a default page.
Uncommenting the following line in host file worked for me,
#127.0.0.1 localhost
Well you are getting a 404, so the web server is running, it just can't find the file.
Check the http.conf file. If it pointing to the right root directory?
If you are using different ports, then check http.conf to see if Apache is listening on the right port, or if apache is redirecting traffic on the port to anther root directory.
Maybe posting your http.conf file might help?
If you're still having this problem, try this:
Edit your hosts file (with elevated privileges)
Uncomment the line "#127.0.0.1 localhost" (ie- remove the #)
Save the file as is. hosts with no extension
In Win7 MS has decided to comment the localhost line with that msg that says it's handled in dns. I'm still not exactly clear what they're getting at, except maybe that they're telling folks to use dns for localhost resolution instead of the hosts file. Probably safer that way, anyway.
Yea, this was a pain for me as well.
So what i did was find the "Start Wampserver", just hit the start button and type it in.
Then right click on it , select properties.
I set it to run in XP servive pack 3 on the capatability tab.
I also checked the box "Run this program as an administrator".
Then I right clicked the WAMPSERVER on the System Tray, and re-started all services.
This worked perfect for me, hope this will help you as well.
Rob
Got any other Programs running ? msn ect... ? some bind to port 8080 then your webserver wouldnt start and would cause a 404 , try binding it to a different port 80 which its default should be
I got a 404 could not connect error then I set wampmanager.exe to run as Xp Sp3 and it seems to be working fine this can be done by
Right Clicking on it
Properties
click tab labled "Compatibility"
Tick Box just undeder "Compatibility
mode"
Select Windows XP (Service Pack 3)
Click Apply then OK
It was Skype interfering for me too. I changed the Skype settings (in Skype go to Tools > options > advanced > Connection and UNCHECK "use port 80 and 443 as alternatives for incoming connections") save then close Skype. I have Win 7 HomePremium 64 bit, had installed Xampp fine with MySQL running fine, but no matter how many times I started Apache (and console showed "Apache started") I still got the "firefox can't establish a connection" error in the browser. After Skype changes were saved, Apache showed the green "Running" and all working now thanks
For me this did the trick at port 80 in the end:
You have to disable the http.sys service manually via the registry:
Launch RegEdit:
Go to: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP
Add a new DWORD (32-bit) value
Name it ‘NoRun’ not including the quotes
Double click the new property
In the Value data field type ’1' not including quotes and click OK
Re-boot your computer
You should now find that Apache will start on port 80!
Have you try the iis? Go to Control Panel->Programs and Features->Turn Windows features on or off (side bar). Try installing or reinstalling the Internet Information Service. I've a windows 7 with iis, with .net and php, and it works great...
you have to install the service, go to wamp->Apache->Service->Install service, then a command prompt window will pop up, then press enter, and after a few seconds go to the same route Services-> and click Start/Resume service, and you ready
I had the exact same issue, and the solution is what someone has already said:
In the taskbar, click on the WAMP icon.
Go to Apache-->Service-->Install Service
Then go back by clicking and selecting Apache-->Service-->Start/Resume Service
This will allow the localhost function to work (keep in mind I had already changed the host file located under c:\windows\system32\drivers\etc to remove the # from the 127.0.0.1 line)
If you need to edit that file still, you need to right click on it and select Properties. Then go to the Security tab, and click the Advanced button. You then need to select the Users, click Edit and select "Full Control". This will enable you to edit it.
That being said, you need to ALSO install the MySQL service following the same procedure.
MySQL-->Service-->Install Service
Then go back by right clicking yet again and selecting MySQL-->Service-->Start/Resume Service.
And that should fix it all up in Windows 7!
Before installing Wamp, go to controlpanel=> Adminstrative tools => IIS Manager and turn off the IIS server. Install wamp and everything works fine. When IIS is on it also uses port 80. You can go through a lot of changing the ports and permissions for wamp but I have found this the quickest and easiest method of getting wamp to run successfully.
Try adding the following tags in the wwwroot folder web.config file. These tags should be added as a child of the configuration tags as below.
-configuration-
--system.webServer--
---validation validateIntegratedModeConfiguration="false" ---
--/system.webServer--
-/configuration-
Maybe Skype or other Application is using port 80.
This you can check in
Tools->Settings->Advanced->Connection
See the above solutions are very good.But whenever you get this 404 eroor,first see this.I am sure the problem will be solved...
Just go to httpd.conf file by clicking wamp server symbol in bottom right taskbar-Apache->httpd.conf... or c:\\wampt\\bin\\apache\\apache2.2.1\\conf\\httpd.conf and approximate on line no 46 you will find "Listen 80"...just make sure it is written "80" after Listen...if it not then change it to 80...And your problem will be solved...
Assuming there is no problem doing a lookup on localhost (to 127.0.0.1), you need to make sure your server is listening to 127.0.0.1.
netstat works in both windows an UNIX. You probably need "netstat -a" to display listeners.

Categories