Jump to content

xmuzukerx

Members
  • Posts

    14
  • Joined

  • Last visited

xmuzukerx's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. thank you, it worked and does sent sms to each recipient, but may i know what kind of validation that ensure data coming? for example?
  2. I'll try to explain as detail as i can The error is at the foreach (line 68). whereby it says Warning: Invalid argument supplied for foreach() in C:\xampp\...on line 68 Reason: I want to use the foreach loop in order to send sms to more than one recipient, and when i try, this form can only send sms towards one recipient only, if i add 4 recipient number, it only send sms to the last recipient, the remaining 3 recipient did not get the sms, can someone help me on how to make it send to every recipient <SCRIPT language="javascript"> function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var cell1 = row.insertCell(0); var element1 = document.createElement("input"); element1.type = "checkbox"; element1.name="chkbox[]"; cell1.appendChild(element1); var cell2 = row.insertCell(1); cell2.innerHTML = rowCount + 1; var cell3 = row.insertCell(2); var element2 = document.createElement("input"); element2.type = "text"; element2.name = "CTL_TEL"; cell3.appendChild(element2); } function deleteRow(tableID) { try { var table = document.getElementById(tableID); var rowCount = table.rows.length; for(var i=0; i<rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0]; if(null != chkbox && true == chkbox.checked) { table.deleteRow(i); rowCount--; i--; } } }catch(e) { alert(e); } } </SCRIPT> <?php error_reporting(E_ALL ^ E_NOTICE); //Example $gsm_send_sms = new gsm_send_sms(); $gsm_send_sms->debug = false; $gsm_send_sms->port = 'COM6'; $gsm_send_sms->baud = 115200; $gsm_send_sms->init(); $name="CTL_TEL[]"; foreach ($tel as $_POST['CTL_TEL']) { $status = $gsm_send_sms->send($_POST["CTL_TEL"] , $_POST["CTL_MSG"]); $status = $gsm_send_sms->send($tel , $_POST["CTL_MSG"]); if ($status) { echo "Message sent\n"; } else { echo "Message not sent\n"; } } $gsm_send_sms->close(); //Send SMS via serial SMS modem class gsm_send_sms { public $port = 'COM6'; public $baud = 115200; public $debug = false; private $fp; private $buffer; //Setup COM port public function init() { $this->debugmsg("Setting up port: \"{$this->port} @ \"{$this->baud}\" baud"); exec("MODE {$this->port}: BAUD={$this->baud} PARITY=N DATA=8 STOP=1", $output, $retval); if ($retval != 0) { throw new Exception('Unable to setup COM port, check it is correct'); } $this->debugmsg(implode("\n", $output)); $this->debugmsg("Opening port"); //Open COM port $this->fp = fopen($this->port . ':', 'r+'); //Check port opened if (!$this->fp) { throw new Exception("Unable to open port \"{$this->port}\""); } $this->debugmsg("Port opened"); $this->debugmsg("Checking for responce from modem"); //Check modem connected fputs($this->fp, "AT\r"); //Wait for ok $status = $this->wait_reply("OK\r\n", 5); if (!$status) { throw new Exception('Did not receive responce from modem'); } $this->debugmsg('Modem connected'); //Set modem to SMS text mode $this->debugmsg('Setting text mode'); fputs($this->fp, "AT+CMGF=1\r"); $status = $this->wait_reply("OK\r\n", 5); if (!$status) { throw new Exception('Unable to set text mode'); } $this->debugmsg('Text mode set'); } //Wait for reply from modem private function wait_reply($expected_result, $timeout) { $this->debugmsg("Waiting {$timeout} seconds for expected result"); //Clear buffer $this->buffer = ''; //Set timeout $timeoutat = time() + $timeout; //Loop until timeout reached (or expected result found) do { $this->debugmsg('Now: ' . time() . ", Timeout at: {$timeoutat}"); $buffer = fread($this->fp, 1024); $this->buffer .= $buffer; usleep(200000);//0.2 sec $this->debugmsg("Received: {$buffer}"); //Check if received expected responce if (preg_match('/'.preg_quote($expected_result, '/').'$/', $this->buffer)) { $this->debugmsg('Found match'); return true; //break; } else if (preg_match('/\+CMS ERROR\:\ \d{1,3}\r\n$/', $this->buffer)) { return false; } } while ($timeoutat > time()); $this->debugmsg('Timed out'); return false; } //Print debug messages private function debugmsg($message) { if ($this->debug == true) { $message = preg_replace("%[^\040-\176\n\t]%", '', $message); echo $message . "\n"; } } //Close port public function close() { $this->debugmsg('Closing port'); fclose($this->fp); } //Send message public function send($tel, $message) { //Filter tel $tel = preg_replace("%[^0-9\+]%", '', $tel); //Filter message text $message = preg_replace("%[^\040-\176\r\n\t]%", '', $message); $this->debugmsg("Sending message \"{$message}\" to \"{$tel}\""); //Start sending of message fputs($this->fp, "AT+CMGS=\"{$tel}\"\r"); //Wait for confirmation $status = $this->wait_reply("\r\n> ", 5); if (!$status) { //throw new Exception('Did not receive confirmation from modem'); $this->debugmsg('Did not receive confirmation from modem'); return false; } //Send message text fputs($this->fp, $message); //Send message finished indicator fputs($this->fp, chr(26)); //Wait for confirmation $status = $this->wait_reply("OK\r\n", 180); if (!$status) { //throw new Exception('Did not receive confirmation of messgage sent'); $this->debugmsg('Did not receive confirmation of messgage sent'); return false; } $this->debugmsg("Message sent"); return true; } } ?> <html> <head> <title>SMS via GSM</title> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> <style> .clbody { font-family:Verdana, Arial, Helvetica, sans-serif; font-size:9pt; font-weight:normal; } .clfooter { font-family:Verdana; font-size:7pt; font-weight:normal; } h1, .h1 { width:100%; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:18px; font-weight:bold; } hr, .hr { color:#b0b0b0; } </style> </head> <body class="clbody"> <h1>SMS via GSM</h1> <div style="WIDTH:700px"> </div> <hr size="1"> <?php error_reporting(E_ALL ^ E_NOTICE); ?> <form action="" method="post" name="myForm"> <table class ="clbody" width="700" border="1"> <tr> <td valign="top">Recipient:</td> <td valign="top"> <INPUT type="button" value="Add Row" onclick="addRow('dataTable')" /> <INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" /> <TABLE id="dataTable" width="350px" border="1"> <TR> <TD><INPUT type="checkbox" name="chk"/></TD> <TD> 1 </TD> <TD> <input type="text" name="CTL_TEL" value="<?php echo $_GET['CTL_TEL']; ?>"> </TD> </TR> </TABLE> </td> </tr> <tr> <td valign="top">Message:</td> <td valign="top"> <input style="width: 250px" type="text" name="CTL_MSG" value="<?php echo $_GET['CTL_MSG']; ?>"></td> </tr> <tr> <td valign="top">Result code:<font color=green></td> <td valign="top"></td> </tr> <tr> <td valign="top"> </td> <td valign="top"><input size="25" type="submit" value="Send" name="CTL_SEND" style="height: 23px; width: 250px"></td> </tr> </table> <br> <br> </form> </body> </html>
  3. Sorry...i'm just asking for help, to create a successful foreach loop that can sent to many recipient...thats all i need
  4. i've known the error but cant find a way to create a foreach loop whereby it will send a sms towards every recipient entered in the form, here's the part where looping is done <?php error_reporting(E_ALL ^ E_NOTICE); //Example $gsm_send_sms = new gsm_send_sms(); $gsm_send_sms->debug = false; $gsm_send_sms->port = 'COM6'; $gsm_send_sms->baud = 115200; $gsm_send_sms->init(); $name="CTL_TEL[]"; foreach ($_POST['CTL_TEL'] as $tel) { $status = $gsm_send_sms->send($_POST["CTL_TEL"] , $_POST["CTL_MSG"]); $status = $gsm_send_sms->send($tel , $_POST["CTL_MSG"]); if ($status) { echo "Message sent\n"; } else { echo "Message not sent\n"; } } $gsm_send_sms->close();
  5. Sorry, the error is right here, when i try to compile, it says Warning: Invalid argument supplied for foreach() on line 68 <SCRIPT language="javascript"> function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var cell1 = row.insertCell(0); var element1 = document.createElement("input"); element1.type = "checkbox"; element1.name="chkbox[]"; cell1.appendChild(element1); var cell2 = row.insertCell(1); cell2.innerHTML = rowCount + 1; var cell3 = row.insertCell(2); var element2 = document.createElement("input"); element2.type = "text"; element2.name = "CTL_TEL"; cell3.appendChild(element2); } function deleteRow(tableID) { try { var table = document.getElementById(tableID); var rowCount = table.rows.length; for(var i=0; i<rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0]; if(null != chkbox && true == chkbox.checked) { table.deleteRow(i); rowCount--; i--; } } }catch(e) { alert(e); } } </SCRIPT> <?php error_reporting(E_ALL ^ E_NOTICE); //Example $gsm_send_sms = new gsm_send_sms(); $gsm_send_sms->debug = false; $gsm_send_sms->port = 'COM6'; $gsm_send_sms->baud = 115200; $gsm_send_sms->init(); $name="CTL_TEL[]"; foreach ($tel as $_POST['CTL_TEL']) { $status = $gsm_send_sms->send($_POST["CTL_TEL"] , $_POST["CTL_MSG"]); $status = $gsm_send_sms->send($tel , $_POST["CTL_MSG"]); if ($status) { echo "Message sent\n"; } else { echo "Message not sent\n"; } } $gsm_send_sms->close(); //Send SMS via serial SMS modem class gsm_send_sms { public $port = 'COM6'; public $baud = 115200; public $debug = false; private $fp; private $buffer; //Setup COM port public function init() { $this->debugmsg("Setting up port: \"{$this->port} @ \"{$this->baud}\" baud"); exec("MODE {$this->port}: BAUD={$this->baud} PARITY=N DATA=8 STOP=1", $output, $retval); if ($retval != 0) { throw new Exception('Unable to setup COM port, check it is correct'); } $this->debugmsg(implode("\n", $output)); $this->debugmsg("Opening port"); //Open COM port $this->fp = fopen($this->port . ':', 'r+'); //Check port opened if (!$this->fp) { throw new Exception("Unable to open port \"{$this->port}\""); } $this->debugmsg("Port opened"); $this->debugmsg("Checking for responce from modem"); //Check modem connected fputs($this->fp, "AT\r"); //Wait for ok $status = $this->wait_reply("OK\r\n", 5); if (!$status) { throw new Exception('Did not receive responce from modem'); } $this->debugmsg('Modem connected'); //Set modem to SMS text mode $this->debugmsg('Setting text mode'); fputs($this->fp, "AT+CMGF=1\r"); $status = $this->wait_reply("OK\r\n", 5); if (!$status) { throw new Exception('Unable to set text mode'); } $this->debugmsg('Text mode set'); } //Wait for reply from modem private function wait_reply($expected_result, $timeout) { $this->debugmsg("Waiting {$timeout} seconds for expected result"); //Clear buffer $this->buffer = ''; //Set timeout $timeoutat = time() + $timeout; //Loop until timeout reached (or expected result found) do { $this->debugmsg('Now: ' . time() . ", Timeout at: {$timeoutat}"); $buffer = fread($this->fp, 1024); $this->buffer .= $buffer; usleep(200000);//0.2 sec $this->debugmsg("Received: {$buffer}"); //Check if received expected responce if (preg_match('/'.preg_quote($expected_result, '/').'$/', $this->buffer)) { $this->debugmsg('Found match'); return true; //break; } else if (preg_match('/\+CMS ERROR\:\ \d{1,3}\r\n$/', $this->buffer)) { return false; } } while ($timeoutat > time()); $this->debugmsg('Timed out'); return false; } //Print debug messages private function debugmsg($message) { if ($this->debug == true) { $message = preg_replace("%[^\040-\176\n\t]%", '', $message); echo $message . "\n"; } } //Close port public function close() { $this->debugmsg('Closing port'); fclose($this->fp); } //Send message public function send($tel, $message) { //Filter tel $tel = preg_replace("%[^0-9\+]%", '', $tel); //Filter message text $message = preg_replace("%[^\040-\176\r\n\t]%", '', $message); $this->debugmsg("Sending message \"{$message}\" to \"{$tel}\""); //Start sending of message fputs($this->fp, "AT+CMGS=\"{$tel}\"\r"); //Wait for confirmation $status = $this->wait_reply("\r\n> ", 5); if (!$status) { //throw new Exception('Did not receive confirmation from modem'); $this->debugmsg('Did not receive confirmation from modem'); return false; } //Send message text fputs($this->fp, $message); //Send message finished indicator fputs($this->fp, chr(26)); //Wait for confirmation $status = $this->wait_reply("OK\r\n", 180); if (!$status) { //throw new Exception('Did not receive confirmation of messgage sent'); $this->debugmsg('Did not receive confirmation of messgage sent'); return false; } $this->debugmsg("Message sent"); return true; } } ?> <html> <head> <title>SMS via GSM</title> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> <style> .clbody { font-family:Verdana, Arial, Helvetica, sans-serif; font-size:9pt; font-weight:normal; } .clfooter { font-family:Verdana; font-size:7pt; font-weight:normal; } h1, .h1 { width:100%; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:18px; font-weight:bold; } hr, .hr { color:#b0b0b0; } </style> </head> <body class="clbody"> <h1>SMS via GSM</h1> <div style="WIDTH:700px"> </div> <hr size="1"> <?php error_reporting(E_ALL ^ E_NOTICE); ?> <form action="" method="post" name="myForm"> <table class ="clbody" width="700" border="1"> <tr> <td valign="top">Recipient:</td> <td valign="top"> <INPUT type="button" value="Add Row" onclick="addRow('dataTable')" /> <INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" /> <TABLE id="dataTable" width="350px" border="1"> <TR> <TD><INPUT type="checkbox" name="chk"/></TD> <TD> 1 </TD> <TD> <input type="text" name="CTL_TEL" value="<?php echo $_GET['CTL_TEL']; ?>"> </TD> </TR> </TABLE> </td> </tr> <tr> <td valign="top">Message:</td> <td valign="top"> <input style="width: 250px" type="text" name="CTL_MSG" value="<?php echo $_GET['CTL_MSG']; ?>"></td> </tr> <tr> <td valign="top">Result code:<font color=green></td> <td valign="top"></td> </tr> <tr> <td valign="top"> </td> <td valign="top"><input size="25" type="submit" value="Send" name="CTL_SEND" style="height: 23px; width: 250px"></td> </tr> </table> <br> <br> </form> </body> </html>
  6. Hello! I wanna create a form that can send sms to multiple recipient, i've created a form that uses javascript to add or remove textbox dynamically, this code successfully send sms when i fill one recipient number, but fails to send more than one recipient, and as i try to make it send sms to more than one user by making it loop, i get this error, Can someone help? i want to know how do i make this form sends sms towards multiple user Warning: Invalid argument supplied for foreach() <SCRIPT language="javascript"> function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var cell1 = row.insertCell(0); var element1 = document.createElement("input"); element1.type = "checkbox"; element1.name="chkbox[]"; cell1.appendChild(element1); var cell2 = row.insertCell(1); cell2.innerHTML = rowCount + 1; var cell3 = row.insertCell(2); var element2 = document.createElement("input"); element2.type = "text"; element2.name = "CTL_TEL"; cell3.appendChild(element2); } function deleteRow(tableID) { try { var table = document.getElementById(tableID); var rowCount = table.rows.length; for(var i=0; i<rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0]; if(null != chkbox && true == chkbox.checked) { table.deleteRow(i); rowCount--; i--; } } }catch(e) { alert(e); } } </SCRIPT> <?php error_reporting(E_ALL ^ E_NOTICE); //Example $gsm_send_sms = new gsm_send_sms(); $gsm_send_sms->debug = false; $gsm_send_sms->port = 'COM6'; $gsm_send_sms->baud = 115200; $gsm_send_sms->init(); $name="CTL_TEL[]"; foreach ($tel as $_POST['CTL_TEL']) { $status = $gsm_send_sms->send($_POST["CTL_TEL"] , $_POST["CTL_MSG"]); $status = $gsm_send_sms->send($tel , $_POST["CTL_MSG"]); if ($status) { echo "Message sent\n"; } else { echo "Message not sent\n"; } } $gsm_send_sms->close(); //Send SMS via serial SMS modem class gsm_send_sms { public $port = 'COM6'; public $baud = 115200; public $debug = false; private $fp; private $buffer; //Setup COM port public function init() { $this->debugmsg("Setting up port: \"{$this->port} @ \"{$this->baud}\" baud"); exec("MODE {$this->port}: BAUD={$this->baud} PARITY=N DATA=8 STOP=1", $output, $retval); if ($retval != 0) { throw new Exception('Unable to setup COM port, check it is correct'); } $this->debugmsg(implode("\n", $output)); $this->debugmsg("Opening port"); //Open COM port $this->fp = fopen($this->port . ':', 'r+'); //Check port opened if (!$this->fp) { throw new Exception("Unable to open port \"{$this->port}\""); } $this->debugmsg("Port opened"); $this->debugmsg("Checking for responce from modem"); //Check modem connected fputs($this->fp, "AT\r"); //Wait for ok $status = $this->wait_reply("OK\r\n", 5); if (!$status) { throw new Exception('Did not receive responce from modem'); } $this->debugmsg('Modem connected'); //Set modem to SMS text mode $this->debugmsg('Setting text mode'); fputs($this->fp, "AT+CMGF=1\r"); $status = $this->wait_reply("OK\r\n", 5); if (!$status) { throw new Exception('Unable to set text mode'); } $this->debugmsg('Text mode set'); } //Wait for reply from modem private function wait_reply($expected_result, $timeout) { $this->debugmsg("Waiting {$timeout} seconds for expected result"); //Clear buffer $this->buffer = ''; //Set timeout $timeoutat = time() + $timeout; //Loop until timeout reached (or expected result found) do { $this->debugmsg('Now: ' . time() . ", Timeout at: {$timeoutat}"); $buffer = fread($this->fp, 1024); $this->buffer .= $buffer; usleep(200000);//0.2 sec $this->debugmsg("Received: {$buffer}"); //Check if received expected responce if (preg_match('/'.preg_quote($expected_result, '/').'$/', $this->buffer)) { $this->debugmsg('Found match'); return true; //break; } else if (preg_match('/\+CMS ERROR\:\ \d{1,3}\r\n$/', $this->buffer)) { return false; } } while ($timeoutat > time()); $this->debugmsg('Timed out'); return false; } //Print debug messages private function debugmsg($message) { if ($this->debug == true) { $message = preg_replace("%[^\040-\176\n\t]%", '', $message); echo $message . "\n"; } } //Close port public function close() { $this->debugmsg('Closing port'); fclose($this->fp); } //Send message public function send($tel, $message) { //Filter tel $tel = preg_replace("%[^0-9\+]%", '', $tel); //Filter message text $message = preg_replace("%[^\040-\176\r\n\t]%", '', $message); $this->debugmsg("Sending message \"{$message}\" to \"{$tel}\""); //Start sending of message fputs($this->fp, "AT+CMGS=\"{$tel}\"\r"); //Wait for confirmation $status = $this->wait_reply("\r\n> ", 5); if (!$status) { //throw new Exception('Did not receive confirmation from modem'); $this->debugmsg('Did not receive confirmation from modem'); return false; } //Send message text fputs($this->fp, $message); //Send message finished indicator fputs($this->fp, chr(26)); //Wait for confirmation $status = $this->wait_reply("OK\r\n", 180); if (!$status) { //throw new Exception('Did not receive confirmation of messgage sent'); $this->debugmsg('Did not receive confirmation of messgage sent'); return false; } $this->debugmsg("Message sent"); return true; } } ?> <html> <head> <title>SMS via GSM</title> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> <style> .clbody { font-family:Verdana, Arial, Helvetica, sans-serif; font-size:9pt; font-weight:normal; } .clfooter { font-family:Verdana; font-size:7pt; font-weight:normal; } h1, .h1 { width:100%; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:18px; font-weight:bold; } hr, .hr { color:#b0b0b0; } </style> </head> <body class="clbody"> <h1>SMS via GSM</h1> <div style="WIDTH:700px"> </div> <hr size="1"> <?php error_reporting(E_ALL ^ E_NOTICE); ?> <form action="" method="post" name="myForm"> <table class ="clbody" width="700" border="1"> <tr> <td valign="top">Recipient:</td> <td valign="top"> <INPUT type="button" value="Add Row" onclick="addRow('dataTable')" /> <INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" /> <TABLE id="dataTable" width="350px" border="1"> <TR> <TD><INPUT type="checkbox" name="chk"/></TD> <TD> 1 </TD> <TD> <input type="text" name="CTL_TEL" value="<?php echo $_GET['CTL_TEL']; ?>"> </TD> </TR> </TABLE> </td> </tr> <tr> <td valign="top">Message:</td> <td valign="top"> <input style="width: 250px" type="text" name="CTL_MSG" value="<?php echo $_GET['CTL_MSG']; ?>"></td> </tr> <tr> <td valign="top">Result code:<font color=green></td> <td valign="top"></td> </tr> <tr> <td valign="top"> </td> <td valign="top"><input size="25" type="submit" value="Send" name="CTL_SEND" style="height: 23px; width: 250px"></td> </tr> </table> <br> <br> </form> </body> </html>
  7. can i know how to put it? sorry still newbie
  8. Hello, i want to make my form detects more than one duplicate entry, my coding here now only detects duplicate username only, how can i make it detects other things not just username only? Can someone fix my code here? <?php include "db_connect.php"; if( isset( $_SESSION['username'] ) ) { $username = $_SESSION['username']; //echo $username; $result = mysql_query("SELECT * FROM users WHERE username = '$username'",$link) or die ("Database Error"); while ($row = mysql_fetch_assoc($result)) { $userLevel = $row['userlevel']; //echo $userLevel; } } ?> <?php include "db_connect.php"; error_reporting(E_ALL ^ E_NOTICE); $name = $_POST['name']; $username = $_POST['username']; $email = $_POST['email']; $password = md5 ($_POST['password']); $matrix = $_POST['matrix']; $date= date("Y-m-d"); $phone = $_POST['phone']; //$sql="SELECT matrix FROM registering WHERE matrix='".$_POST['matrix']."'"; //$query= mysql_query($sql); //$row=mysql_num_rows($query); if (empty($_POST['matrix'])){ echo 'Please insert matrix number'; } else{ //if($row == 0){ // echo "No matrix in database...Please contact admin to register<br />"; //} //else{ $sql2="INSERT INTO users(matrix, name , username , email , password , date , phone) VALUES ('".$matrix."','".$name."','".$username."','".$email."','".$password."','".$date."', '".$phone."')"; mysql_query($sql2) or die ('<center><h1><font color=red>Error Updating Database! <br>Username already in database!. <br>Please choose another username<br><br><INPUT Type="button" VALUE="Back" onClick="history.go(-1);return true;">'); echo "Registration Successful!<br />"; echo "Please go to [<a href='index.php'>Main Page</a>] to login.."; } //} ?>
  9. Hi! i'm currently have a problem using PHP in order to create a form that has the capability to send sms by using GSM modem, by the way, the modem that i'm using right now is Huawei E173 Broadband. I know there has been a lot of way to send sms using php but most of it is by using SMS Gateway, (eg like nowsms) To the problem, I wanna know how do i make this form below to send sms, now i've know that my modem is on COM6, so how do i integrate this form below here with GSM modem to send sms by using php+ So now i really need help here to teach me and guide me so that i can make php uses gsm modem to send sms. Thank you so much! Form: <html> <head> <title>FORM TEST</title> </head> <body> <form name="form1" action="" method="post"> Enter Mobile Number: <input type="text" name="text1"><br> Enter SMS: <textarea cols="10" rows="10" name="text2"></textarea><br> <input type="submit" name="submit1" value="Send SMS"> </form> </body> </html> To make this form integrae with code below to send sms example.php (my modem is using COM6) <?php include "php_serial.class.php"; // Let's start the class $serial = new phpSerial; // First we must specify the device. This works on both linux and windows (if // your linux serial device is /dev/ttyS0 for COM1, etc) $serial->deviceSet("COM6"); // Then we need to open it $serial->deviceOpen(); // To write into $serial->sendMessage("Hello !"); // Or to read from $read = $serial->readPort(); // If you want to change the configuration, the device must be closed $serial->deviceClose(); // We can change the baud rate $serial->confBaudRate(2400); // etc... ?> php_serial_class.php - to initialize send sms <?php define ("SERIAL_DEVICE_NOTSET", 0); define ("SERIAL_DEVICE_SET", 1); define ("SERIAL_DEVICE_OPENED", 2); /** * Serial port control class * * THIS PROGRAM COMES WITH ABSOLUTELY NO WARANTIES ! * USE IT AT YOUR OWN RISKS ! * * @author Rémy Sanchez <thenux@gmail.com> * @thanks Aurélien Derouineau for finding how to open serial ports with windows * @thanks Alec Avedisyan for help and testing with reading * @copyright under GPL 2 licence */ class phpSerial { var $_device = null; var $_windevice = null; var $_dHandle = null; var $_dState = SERIAL_DEVICE_NOTSET; var $_buffer = ""; var $_os = ""; /** * This var says if buffer should be flushed by sendMessage (true) or manualy (false) * * @var bool */ var $autoflush = true; /** * Constructor. Perform some checks about the OS and setserial * * @return phpSerial */ function phpSerial () { setlocale(LC_ALL, "en_US"); $sysname = php_uname(); if (substr($sysname, 0, 5) === "Linux") { $this->_os = "linux"; if($this->_exec("stty --version") === 0) { register_shutdown_function(array($this, "deviceClose")); } else { trigger_error("No stty availible, unable to run.", E_USER_ERROR); } } elseif(substr($sysname, 0, 7) === "Windows") { $this->_os = "windows"; register_shutdown_function(array($this, "deviceClose")); } else { trigger_error("Host OS is neither linux nor windows, unable tu run.", E_USER_ERROR); exit(); } } // // OPEN/CLOSE DEVICE SECTION -- {START} // /** * Device set function : used to set the device name/address. * -> linux : use the device address, like /dev/ttyS0 * -> windows : use the COMxx device name, like COM1 (can also be used * with linux) * * @param string $device the name of the device to be used * @return bool */ function deviceSet ($device) { if ($this->_dState !== SERIAL_DEVICE_OPENED) { if ($this->_os === "linux") { if (preg_match("@^COM(\d+):?$@i", $device, $matches)) { $device = "/dev/ttyS" . ($matches[1] - 1); } if ($this->_exec("stty -F " . $device) === 0) { $this->_device = $device; $this->_dState = SERIAL_DEVICE_SET; return true; } } elseif ($this->_os === "windows") { if (preg_match("@^COM(\d+):?$@i", $device, $matches) and $this->_exec(exec("mode " . $device)) === 0) { $this->_windevice = "COM" . $matches[1]; $this->_device = "\\.\com" . $matches[1]; $this->_dState = SERIAL_DEVICE_SET; return true; } } trigger_error("Specified serial port is not valid", E_USER_WARNING); return false; } else { trigger_error("You must close your device before to set an other one", E_USER_WARNING); return false; } } /** * Opens the device for reading and/or writing. * * @param string $mode Opening mode : same parameter as fopen() * @return bool */ function deviceOpen ($mode = "r+b") { if ($this->_dState === SERIAL_DEVICE_OPENED) { trigger_error("The device is already opened", E_USER_NOTICE); return true; } if ($this->_dState === SERIAL_DEVICE_NOTSET) { trigger_error("The device must be set before to be open", E_USER_WARNING); return false; } if (!preg_match("@^[raw]\+?b?$@", $mode)) { trigger_error("Invalid opening mode : ".$mode.". Use fopen() modes.", E_USER_WARNING); return false; } $this->_dHandle = @fopen($this->_device, $mode); if ($this->_dHandle !== false) { stream_set_blocking($this->_dHandle, 0); $this->_dState = SERIAL_DEVICE_OPENED; return true; } $this->_dHandle = null; trigger_error("Unable to open the device", E_USER_WARNING); return false; } /** * Closes the device * * @return bool */ function deviceClose () { if ($this->_dState !== SERIAL_DEVICE_OPENED) { return true; } if (fclose($this->_dHandle)) { $this->_dHandle = null; $this->_dState = SERIAL_DEVICE_SET; return true; } trigger_error("Unable to close the device", E_USER_ERROR); return false; } // // OPEN/CLOSE DEVICE SECTION -- {STOP} // // // CONFIGURE SECTION -- {START} // /** * Configure the Baud Rate * Possible rates : 110, 150, 300, 600, 1200, 2400, 4800, 9600, 38400, * 57600 and 115200. * * @param int $rate the rate to set the port in * @return bool */ function confBaudRate ($rate) { if ($this->_dState !== SERIAL_DEVICE_SET) { trigger_error("Unable to set the baud rate : the device is either not set or opened", E_USER_WARNING); return false; } $validBauds = array ( 110 => 11, 150 => 15, 300 => 30, 600 => 60, 1200 => 12, 2400 => 24, 4800 => 48, 9600 => 96, 19200 => 19, 38400 => 38400, 57600 => 57600, 115200 => 115200 ); if (isset($validBauds[$rate])) { if ($this->_os === "linux") { $ret = $this->_exec("stty -F " . $this->_device . " " . (int) $rate, $out); } elseif ($this->_os === "windows") { $ret = $this->_exec("mode " . $this->_windevice . " BAUD=" . $validBauds[$rate], $out); } else return false; if ($ret !== 0) { trigger_error ("Unable to set baud rate: " . $out[1], E_USER_WARNING); return false; } } } /** * Configure parity. * Modes : odd, even, none * * @param string $parity one of the modes * @return bool */ function confParity ($parity) { if ($this->_dState !== SERIAL_DEVICE_SET) { trigger_error("Unable to set parity : the device is either not set or opened", E_USER_WARNING); return false; } $args = array( "none" => "-parenb", "odd" => "parenb parodd", "even" => "parenb -parodd", ); if (!isset($args[$parity])) { trigger_error("Parity mode not supported", E_USER_WARNING); return false; } if ($this->_os === "linux") { $ret = $this->_exec("stty -F " . $this->_device . " " . $args[$parity], $out); } else { $ret = $this->_exec("mode " . $this->_windevice . " PARITY=" . $parity{0}, $out); } if ($ret === 0) { return true; } trigger_error("Unable to set parity : " . $out[1], E_USER_WARNING); return false; } /** * Sets the length of a character. * * @param int $int length of a character (5 <= length <= * @return bool */ function confCharacterLength ($int) { if ($this->_dState !== SERIAL_DEVICE_SET) { trigger_error("Unable to set length of a character : the device is either not set or opened", E_USER_WARNING); return false; } $int = (int) $int; if ($int < 5) $int = 5; elseif ($int > $int = 8; if ($this->_os === "linux") { $ret = $this->_exec("stty -F " . $this->_device . " cs" . $int, $out); } else { $ret = $this->_exec("mode " . $this->_windevice . " DATA=" . $int, $out); } if ($ret === 0) { return true; } trigger_error("Unable to set character length : " .$out[1], E_USER_WARNING); return false; } /** * Sets the length of stop bits. * * @param float $length the length of a stop bit. It must be either 1, * 1.5 or 2. 1.5 is not supported under linux and on some computers. * @return bool */ function confStopBits ($length) { if ($this->_dState !== SERIAL_DEVICE_SET) { trigger_error("Unable to set the length of a stop bit : the device is either not set or opened", E_USER_WARNING); return false; } if ($length != 1 and $length != 2 and $length != 1.5 and !($length == 1.5 and $this->_os === "linux")) { trigger_error("Specified stop bit length is invalid", E_USER_WARNING); return false; } if ($this->_os === "linux") { $ret = $this->_exec("stty -F " . $this->_device . " " . (($length == 1) ? "-" : "") . "cstopb", $out); } else { $ret = $this->_exec("mode " . $this->_windevice . " STOP=" . $length, $out); } if ($ret === 0) { return true; } trigger_error("Unable to set stop bit length : " . $out[1], E_USER_WARNING); return false; } /** * Configures the flow control * * @param string $mode Set the flow control mode. Availible modes : * -> "none" : no flow control * -> "rts/cts" : use RTS/CTS handshaking * -> "xon/xoff" : use XON/XOFF protocol * @return bool */ function confFlowControl ($mode) { if ($this->_dState !== SERIAL_DEVICE_SET) { trigger_error("Unable to set flow control mode : the device is either not set or opened", E_USER_WARNING); return false; } $linuxModes = array( "none" => "clocal -crtscts -ixon -ixoff", "rts/cts" => "-clocal crtscts -ixon -ixoff", "xon/xoff" => "-clocal -crtscts ixon ixoff" ); $windowsModes = array( "none" => "xon=off octs=off rts=on", "rts/cts" => "xon=off octs=on rts=hs", "xon/xoff" => "xon=on octs=off rts=on", ); if ($mode !== "none" and $mode !== "rts/cts" and $mode !== "xon/xoff") { trigger_error("Invalid flow control mode specified", E_USER_ERROR); return false; } if ($this->_os === "linux") $ret = $this->_exec("stty -F " . $this->_device . " " . $linuxModes[$mode], $out); else $ret = $this->_exec("mode " . $this->_windevice . " " . $windowsModes[$mode], $out); if ($ret === 0) return true; else { trigger_error("Unable to set flow control : " . $out[1], E_USER_ERROR); return false; } } /** * Sets a setserial parameter (cf man setserial) * NO MORE USEFUL ! * -> No longer supported * -> Only use it if you need it * * @param string $param parameter name * @param string $arg parameter value * @return bool */ function setSetserialFlag ($param, $arg = "") { if (!$this->_ckOpened()) return false; $return = exec ("setserial " . $this->_device . " " . $param . " " . $arg . " 2>&1"); if ($return{0} === "I") { trigger_error("setserial: Invalid flag", E_USER_WARNING); return false; } elseif ($return{0} === "/") { trigger_error("setserial: Error with device file", E_USER_WARNING); return false; } else { return true; } } // // CONFIGURE SECTION -- {STOP} // // // I/O SECTION -- {START} // /** * Sends a string to the device * * @param string $str string to be sent to the device * @param float $waitForReply time to wait for the reply (in seconds) */ function sendMessage ($str, $waitForReply = 0.1) { $this->_buffer .= $str; if ($this->autoflush === true) $this->flush(); usleep((int) ($waitForReply * 1000000)); } /** * Reads the port until no new datas are availible, then return the content. * * @pararm int $count number of characters to be read (will stop before * if less characters are in the buffer) * @return string */ function readPort ($count = 0) { if ($this->_dState !== SERIAL_DEVICE_OPENED) { trigger_error("Device must be opened to read it", E_USER_WARNING); return false; } if ($this->_os === "linux") { $content = ""; $i = 0; if ($count !== 0) { do { if ($i > $count) $content .= fread($this->_dHandle, ($count - $i)); else $content .= fread($this->_dHandle, 128); } while (($i += 128) === strlen($content)); } else { do { $content .= fread($this->_dHandle, 128); } while (($i += 128) === strlen($content)); } return $content; } elseif ($this->_os === "windows") { /* Do nohting : not implented yet */ } trigger_error("Reading serial port is not implemented for Windows", E_USER_WARNING); return false; } /** * Flushes the output buffer * * @return bool */ function flush () { if (!$this->_ckOpened()) return false; if (fwrite($this->_dHandle, $this->_buffer) !== false) { $this->_buffer = ""; return true; } else { $this->_buffer = ""; trigger_error("Error while sending message", E_USER_WARNING); return false; } } // // I/O SECTION -- {STOP} // // // INTERNAL TOOLKIT -- {START} // function _ckOpened() { if ($this->_dState !== SERIAL_DEVICE_OPENED) { trigger_error("Device must be opened", E_USER_WARNING); return false; } return true; } function _ckClosed() { if ($this->_dState !== SERIAL_DEVICE_CLOSED) { trigger_error("Device must be closed", E_USER_WARNING); return false; } return true; } function _exec($cmd, &$out = null) { $desc = array( 1 => array("pipe", "w"), 2 => array("pipe", "w") ); $proc = proc_open($cmd, $desc, $pipes); $ret = stream_get_contents($pipes[1]); $err = stream_get_contents($pipes[2]); fclose($pipes[1]); fclose($pipes[2]); $retVal = proc_close($proc); if (func_num_args() == 2) $out = array($ret, $err); return $retVal; } // // INTERNAL TOOLKIT -- {STOP} // } ?>
  10. i want to make this upload form to display a notification (there is no file chosen) when the submit button is clicked and also to make the submit button allow file that is below 3MB to be uploaded and deny any file that is more than 3MB by displaying message (max file size)
  11. i didnt understand much, tried on some coding on the link, but didnt work like i'm expected
  12. Hello, i have a problem in developing a secure file upload/download system using php, whereby in this code, there is no restriction in choosing any file type, but there is restriction on file size. and the file info will be stored in the database. Problem # i'm stucked in creating a upload form whereby there is an message box popped out saying "there is an error due to no file selected" when i click on the upload button without selecting any file # need help in setting the file size below 3MB whereby if i upload file more than 3MB there will be a message box popped out saying "maximum file size!" instead of showing Undefined index: on top of the browser Here are the code in uploadaction.php here are the form in download.php * the form is on download.php whereby it will refer to uploadaction.php to do the upload i've tried to find code from other sources but it didnt help, would love if javascript coding can be added to improve this coding. Thank you so much~
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.