PHP - Port Status
Hello,
I have a webpage that runs some php code to control electrical devices. One part of it controls outside lights. Another part controls an electric door striker. I keep expanding the functionality of it and need to change one pin of the port without affecting the others. So far I use a different port for each function but I am out of ports so I need to use the different pins of the parallel port. I am using a linux ubuntu server. From my php webpage I issue this command: <?php exec("/home/setSerialSignal /dev/ttyS0 0 0"); ?> which controls the lights using the serial port. I can control 2 pins but I can't check the status of them so if I make a change to one pin it cancels the other. For another one I use the parallel port with this command: <?php exec("/home/parashell 0x378 1"); ?> which turns on pin #2 of the parallel port. Parashell has an executable called "pin". If you type the command "pin 0x378" it will return a value for the status of the parallel port. "1" for example which tells me that pin #2 is on. Is there a way to pass this value to a php variable? I am looking to be able to read the status of the port and make changes to just the pin I want. Lets say pin #2 is on and I want to turn pin #3 on. I would have to issue <?php exec("/home/parashell 0x378 2"); ?> to turn pin #3 on, but that would turn off pin #2. If I could pass the "1" from the "pin" command I could add it to the "2" and give it the command with a variable as "3". Thanks in advance for any help you can give. I hope I explained it ok and didn't confuse everyone. Similar TutorialsHi, I upgraded my XAMPP to the version 1.8.3 (win32) recently. Apache failed to start and I got the following error Stupid question but why would it need the port contained inside the URL for redirection later on? Code: [Select] /* The servername and serverport tells PayPal where the buyer should be directed back to after authorizing payment. In this case, its the local webserver that is running this script Using the servername and serverport, the return URL is the first portion of the URL that buyers will return to after authorizing payment */ $serverName = $_SERVER['SERVER_NAME']; $serverPort = $_SERVER['SERVER_PORT']; $url=dirname('http://'.$serverName.':'.$serverPort.$_SERVER['REQUEST_URI']); Hi!
I'm trying to make an button that when it's pressed sends an http post to my home server. But my home server is runing on port 84 and i think that i'm not being able to send the post correctly because of this port. any help?
my code now is this:
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://homeserver.net:84/?device=35"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch);The way I have the URL is correct? thanks! Okay, I'm using fsockopen to see if a port is being used, But all it does it crashes the page if it isn't. If it is one it works but if it is off the pages just doesn't load at all. Code: <?php $fp=fsockopen("localhost", 43594, $errno, $errstr, 30); if($fp){ echo('The server is <font color="#0066FF"><b>Online!</b></font>'); } else { echo('The server is <font color="#FF0000"><b>Offline!</b></font>'); } ?> Can one of you amazing helpful souls help me out? Thanks in advance! Hi all,
I want to send a string of data to serial port. Below is the code. Sdata contains the string. for example "<LT-ON-50>".
<?php exec("mode com3: BAUD=600 PARITY=n DATA=8 STOP=1 to=off dtr=off rts=off"); if (isset($_GET['action'])) { $SData = $_GET['action']; $fp = fopen("com3","w"); fwrite($fp,$SData); fclose($fp); } ?>unfortunately, it will send only one character i.e '<'. the remaining characters will be lost. What could be wrong in the code. Any help can be greatly appreciated. Thanks, Hi. I am writing a web app to control Zoom Player on my HTPC. I found that ZP supports listening on a TCP port to accept control commands. The docs say to quit ZP, send 5100,fnExit + ASCII 13/10 to port 4769. My original client was C# and I implemented it there, works great. I then realized WTF am I doing using an external .EXE to just send data to a TCP port? Switched to using PHP's fsockopen. Alas, that causes an error to pop up on ZP (List index out of bounds or some such). Perplexed, I wrote a GUI for the HTPC to just display an ASCII val breakdown of what it receives to compa So it looks like they both send the data the same. Any idea why the discrepancy? Here is the code: C# that works: Code: [Select] string cmdstr = ""; for (int x=2; x<=args.Length-1; x++) cmdstr += args[x] + " "; if (SendCommand(args[0], System.Convert.ToInt16(args[1]), cmdstr.Trim() + Environment.NewLine)) Console.WriteLine("Command string sent."); Environment.Exit(0); static bool SendCommand(string dest, int port, string cmd) { try { IPAddress[] ips = Dns.GetHostAddresses(dest); TcpClient client = new TcpClient(); IPEndPoint serverEndPoint = new IPEndPoint(ips[0], port); client.Connect(serverEndPoint); NetworkStream clientStream = client.GetStream(); ASCIIEncoding encoder = new ASCIIEncoding(); byte[] buffer = encoder.GetBytes(cmd); clientStream.Write(buffer, 0, buffer.Length); clientStream.Flush(); clientStream.Close(); clientStream.Dispose(); client.Close(); return true; } catch (Exception ex) { Console.WriteLine("Failed: " + ex.Message); return false; } } The PHP that is being difficult: Code: [Select] send_data("lioth", "4769", "5100,fnExit"); function send_data($host,$port,$data='') { $fp = fsockopen($host,$port); if($fp) { fputs($fp, "$data\r\n"); fclose($fp); } return; } Hi, I'm trying to connect to a database on a port other than 3306 to create a database. Here's my connect code: $connection = new MySQLi($host,$user,$pass)() But according to the PHP website it says I can lay the code out like so: new MySQLi($host,$user,$pass,$database,$port)() But how do I specify the port without the database? I've tried just "" as the database but the connection still fails. Any help would be much appreciated. Hello Is it possible to uses PHP, to grap incoming packets from a port, on the PHP server ?? hello and good day dear joomla-experts well i want to add a business-directory to joomla and want to run this below mentioned code on overpass-turbo.eu see this http://overpass-turbo.eu/s/5pv and include the results into businessdirectory see the option for the code http://overpass-turbo.eu/ [adiff:"2014-07-01T00:00:00Z"]; area[name="Argentina"][boundary=administrative]->.a; ( node (area.a) [amenity=school][website]; way (area.a) [amenity=school][website]; ); out meta geom; and then see the results <?xml version="1.0" encoding="UTF-8"?> <osm version="0.6" generator="Overpass API"> <note>The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.</note> <meta osm_base="2014-10-12T14:10:02Z" areas="2014-10-12T03:37:02Z"/> <action type="modify"> <old> <node id="961544799" lat="-34.6064077" lon="-58.3749056" version="4" timestamp="2013-10-04T06:43:38Z" changeset="18172855" uid="79602" user="Zalitoar"> <tag k="addr:housenumber" v="165"/> <tag k="addr:street" v="Florida"/> <tag k="amenity" v="school"/> <tag k="name" v="IBL - International Bureau of Language"/> <tag k="website" v="http://www.ibl.com.ar"/> </node> </old> <new> <node id="961544799" lat="-34.6065440" lon="-58.3750010" version="5" timestamp="2014-07-11T17:43:16Z" changeset="24086663" uid="79602" user="Zalitoar"> <tag k="addr:housenumber" v="165"/> <tag k="addr:street" v="Florida"/> <tag k="amenity" v="school"/> <tag k="name" v="IBL - International Bureau of Language"/> <tag k="website" v="http://www.ibl.com.ar"/> </node> </new> </action> <action type="modify"> <old> <node id="2512237096" lat="-34.5636728" lon="-58.4422897" version="2" timestamp="2014-01-30T22:19:42Z" changeset="20291654" uid="255141" user="Souchong"> <tag k="addr:housenumber" v="1395"/> <tag k="addr:street" v="Avenida Luis María Campos"/> <tag k="amenity" v="school"/> <tag k="name" v="Método DeRose Belgrano"/> <tag k="phone" v="+54 11 47854882"/> <tag k="website" v="http://derosebelgrano.com.ar/"/> </node> </old> <new> <node id="2512237096" lat="-34.5636835" lon="-58.4423120" version="3" timestamp="2014-08-23T04:01:26Z" changeset="24947372" uid="331218" user="AgusQui"> <tag k="addr:housenumber" v="1395"/> <tag k="addr:street" v="Avenida Luis María Campos"/> <tag k="amenity" v="school"/> <tag k="name" v="Método DeRose Belgrano"/> <tag k="phone" v="+54 11 47854882"/> <tag k="website" v="http://derosebelgrano.com.ar/"/> </node> </new> </action> <action type="create"> <node id="2934940034" lat="-34.6181407" lon="-58.5235741" version="2" timestamp="2014-08-06T03:29:38Z" changeset="24567582" uid="648570" user="Abejo"> <tag k="addr:housenumber" v="5490"/> <tag k="addr:street" v="Simbrón"/> <tag k="amenity" v="school"/> <tag k="name" v="I.M.E.P."/> <tag k="phone" v="+54 011 45676610"/> <tag k="website" v="http://formarfuturo.org.ar"/> </node> </action> <action ty i love to do this - many many thanks for all help hello and good day dear php-freaks which is the passwd for the mysql db run opensuse - therein i have installed a myql serfver and an apache now i want to port over a cms-system from a server to the localhost. question: the passwd of the configuriatin of the cms has got the following db connecgtion host : localhost db-name db-passwd question: does the db passwd need to match the passwd of the local mysql server!? is this true love to hear from you I have a small project. I have a control board that is connected to the parallel port. It controls 8 strips of LED on the LPT1 port. I can turn these on and off via the command prompt, using LPTOUT.exe ie lptout 1 turns on the 1st LED lptout 2 will turn off 1st LED and turn on 2nd, lptout 4 turns on 3rd and 2nd off, etc 1, 2, 4, 8, 16, 32, 64, 128. and combinations ie lptout 3 turns on LEDS 1 and 2, and so on. However lptout seems very unresponsive sometimes I have to do lptout 1 twice before LED 1 turns on. Is there another command I can use to write to LPT1 port. I need some PHP code to control the outputs. I want to sequence the outputs ie 1on (1second) 2on (1 second) 3 on (1 second) 4 on etc. to 8, then all off then repeat. Can anyone help me. THANK YOU. how to arrange a port forward via ssh-tunnel i need to do that on a domain with this syntax https://www2.mydomain.org:2211/ i am on opensuse guess that i firstly have to activate the ssh Hi All - I'm trying to see if the below is possible using PHP. is it possible for php to allow a user to check if a port is open/listening on a remote server/PC, from their local machine. I've seen scripts on the web that talk about opening cmd.exe - this won't work as not all of my users will be on windows. Also saw fsock.. but the remote server is not serving http page(s). Also saw telnet, but again, some of my users may not have that windows feature enabled. Desired workflow: 1. user enters the server hostname/IP and a port 2. my php webapp will emulate checking if that hostname and port is open from the local user's computer.
thanks! Hello guys, I am new to PHP programming. I am trying to figure out how to use PHP language to transmit/write characters to a USB port device at 9600 baud rate 8-N-1. Basically I just need the PHP coding to allow me to send stuff to the USB device but I have no idea how I can interface this. I did some researching but most were for RS-232 COM Port. I can't find the proper one for USB. If someone can help me out, that would be awesome. Thank you! Problem: I'm trying to make it so the array responds to the integer of status in the database. So, to check if it's one, I try this: $get["status"]["1"] = "Message here..."; But, on my result, I'm just getting WWTT - And the value in the database for the ticket is 0. I'm not sure if I'm using the array correctly. My full code: <?php session_start(); include("../includes/mysql.php"); include("../includes/config.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="../style.css" rel="stylesheet" type="text/css" /> <title><?php echo $title; ?></title> </head> <body> <div id="container"> <div id="content"> <div id="left"> <div class="menu"> <?php include("../includes/navigation.php"); ?> <div class="menufooter"></div> </div> <?php include("../includes/menu.php"); ?> </div> <div id="middle"> <?php $existing = $_POST['existing']; $query = mysql_query("SELECT COUNT(id),id,status,date,question,title FROM tickets WHERE id='$existing'"); $get = mysql_fetch_assoc($query); if(!$existing) { echo ' <div class="post"> <div class="postheader"><h1>Error</h1></div> <div class="postcontent"> <p>You have not enetered in a ticket ID. Please go back and do so.</p> </div> <div class="postfooter"></div> </div> '; } elseif($get['COUNT(id)'] < 1) { echo ' <div class="post"> <div class="postheader"><h1>Error</h1></div> <div class="postcontent"> <p>The ticket ID you are trying to use doesnt exist. Please go back or submit another ticket.</p> </div> <div class="postfooter"></div> </div> '; } else { $get["status"]["0"] = "Waiting for support..."; $get["status"]["1"] = "Waiting for user..."; $get["status"]["2"] = "Ticket Closed..."; $get["status"]["3"] = "Ticket Opened..."; echo ' <div class="post"> <div class="postheader"><h1>View Ticket Status - ID '. $get["id"] .'</h1></div> <div class="postcontent"> <p>Title: '. $get["title"] .' - Posted on: '. $get["date"] .'</p> <p>Ticket Status: '. $get["status"] .'</p> <p>Question: '. nl2br($get["question"]) .'</p> </div> <div class="postfooter"></div> </div> '; } ?> </div> </div> </div> </body> </html> I want to know how can i check wether the user is online on my website or not.... I am wanting to echo one of these 4 statements depending on the 'status' value. Currently it is showing the status value on the 2nd line but not the statement below.. Code: [Select] <li> <strong>Status: </strong><?php more_fields('status') ?> <?php if (more_fields('status')=="Red") echo "Your account is currently undergoing judgement"; elseif (more_fields('status')=="Green") echo "Your account is currently Live"; elseif (more_fields('status')=="Yellow") echo "Your account is currently undergoing site visits"; elseif (more_fields('status')=="Blue") echo "Your account is currently undergoing insolvency/liquidation";?> </li> any help appreciated. Thanks, Jake Hi there, i have code that enables a user to login to my site. I have a player table that consists of: PlayerName, Password and Status. The playername and password is what logs the user in however i want to make it so that when a user logs in it automatically sets that users Status to 1. Can some one point me in the right direction please?? Thanks Code: [Select] <?php if (!isset($_SESSION)) { session_start(); } $loginFormAction = $_SERVER['PHP_SELF']; if (isset($_GET['accesscheck'])) { $_SESSION['PrevUrl'] = $_GET['accesscheck']; } if (isset($_POST['textfield'])) { $loginUsername=$_POST['textfield']; $password=$_POST['textfield2']; $MM_fldUserAuthorization = ""; $MM_redirectLoginSuccess = "index.php"; $MM_redirectLoginFailed = "fail.php"; $MM_redirecttoReferrer = false; mysql_select_db($database_swb, $swb); $LoginRS__query=sprintf("SELECT PlayerName, Password FROM player WHERE PlayerName=%s AND Password=%s", GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); $LoginRS = mysql_query($LoginRS__query, $swb) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = ""; //declare two session variables and assign them $_SESSION['MM_Username'] = $loginUsername; $_SESSION['MM_UserGroup'] = $loginStrGroup; if (isset($_SESSION['PrevUrl']) && false) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); } } ?> Thank you Hi, I need to know the delete status of an email. I can able to make the Read status, but whether there is any tricks that we can make in order to know the status of our email (deleted from our users) Any help !! Ty JO Okay I now have a working extract ZIP archive script. What I am now looking to do is have a loop which checks the percentage complete the extraction is and at 100% (with no erros) carry out a PHP function. The code so far is (and includes comments on how the new function would be placed): $dir = opendir('temp'); while(false !==($file=readdir($dir))){ if(strpos($file, '.zip',1)){ extractupdate($file); } } function extractupdate($file){ $zip=new ZipArchive; if($zip->open('temp/'.$file) == TRUE){ $update=rtrim($file, ".zip"); $zip->extractTo($_SERVER['DOCUMENT_ROOT']."/update/temp/$update"); $zip->close(); echo "Extraction started."; // Place loop here to run untill 100% extraction completed and then run function "intsallupdate($update);" } else { echo "Failed to start extraction."; } } function installupdate($update){ // installupdate() will now shift the files around as necessary. // NB to PHPFREAKS, no assistance with code for installupdate() is required, only the loop. Cheers. } Many thanks in advance. |