validation

please I’m trying to validate my php script such that only 15 number digits should pass through. Thanks in advaced

<?php #Version: $Revision: 1.5 $ ########################################################################### #This function will parse the XML data into a CSV format string. ########################################################################### function parsePhone($phoneAndMessage) { $combined = ''; $xml = simplexml_load_string($phoneAndMessage); $message = $xml-> Message ; $phonercpt = $xml-> SenderNumber; $combined = $phonercpt.$message; return $combined ; } function breakBig($bignum) { $endpart = substr($bignum,strpos($bignum,".")-3); $newpart3 = substr($bignum,strpos($bignum,$endpart)-3,3); $newpart4 = substr($bignum,0,strpos($bignum,$newpart3)); $finalstring2 = $newpart4.",".$newpart3.",".$endpart; return $finalstring2; } function breakSmall($smallnum) { $newpart1 = substr($smallnum,strpos($smallnum,".")-3); $newpart2 = substr($smallnum,0,-(strlen($newpart1))); $finalstring = $newpart2.",".$newpart1; return $finalstring; } ############################################################################# #Get the XMLDATA from POST. $sender = $_POST['XMLDATA']; # #This is so that we can pass it as a string to simplexml_load_string() function #If leave as $_POST['XMLDATA'] it just won't work. # $xmlAsALongString .= $sender; #$xmlAsALongString = str_replace('','',$xmlAsALongString); #$xmlAsALongString = str_replace('','',$xmlAsALongString); $newPhoneAndMessage=''; $newPhoneAndMessage.=parsePhone($xmlAsALongString); $phonenumber = substr($newPhoneAndMessage,1,13); $pinnumber = substr($newPhoneAndMessage,14); if(strlen($pinnumber)!=15){ $echostring="your pin no is not upto 15 digits, please check the number and try again"; }else{ sybase_min_server_severity(20); $connection = sybase_connect('PFA_SVR', 'trustfundonlines', 'pensions2'); if(!$connection){ $fp = fopen("connection.txt","a"); fputs($fp,"no connection"); fclose($fp); echo "couldn't make a connection"; }else { $fp = fopen("connection.txt","a"); fputs($fp,"connection made"); fclose($fp); echo "Connection made" ; sybase_select_db("pfa", $connection); $sql = 'SELECT * FROM Sms_balance WHERE Rsapin ="'.$pinnumber.'"'; $sql_result = sybase_query($sql, $connection); $row= sybase_fetch_array($sql_result); $newpin = $row['Rsapin']; $phonecompare = $row['MOBILE_PHONE']; $status = $row['RsaBalance']; $lcyear = $row['LastContYear']; $lcmonth = $row['LastContMonth']; $date = $row['Value_date']; $datecropped = substr($date,0,12); $newstatus = ""; if(strlen($status)>12) { $newstatus.= breakBig($status); } else { $newstatus.= breakSmall($status); } if($phonecompare==$phonenumber) { $echostring = "Dear Customer, Your balance as at ".$datecropped." is ".$newstatus.".Your Last Credit was for ".$lcmonth.", ".$lcyear.". Thank you. For Help, call 08069778760 or 08057003000"; } else { $echostring = "Your mobile no. is not registered on our system, please login to your account online and update your no. or send an email to [email protected]"; } $url = 'http://www.maviscomputel.com/xmlreceiveptf.php'; /** * Initialize handle and set options */ if(strlen($pinnumber)<16) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 4); curl_setopt($ch, CURLOPT_POSTFIELDS, "phone=$phonenumber&message=$echostring"); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: close')); /** * Execute the request and also time the transaction */ $start = array_sum(explode(' ', microtime())); $result = curl_exec($ch); $stop = array_sum(explode(' ', microtime())); $totalTime = $stop - $start; } } } $fp = fopen("receivelogupdatenew.txt","a"); if($newPhoneAndMessage!=null) { fputs($fp,$phonenumber); fputs($fp,\n); fputs($fp,$pinnumber); fputs($fp,\n); fputs($fp,$phonecompare); } else { fputs($fp,"update password not received"); } fclose($fp); #use the information to change the information on the database /** $con = mysql_connect("localhost","root","mysql"); if(!$con) { die('Could not connect: '.mysql_error()); } mysql_select_db("pensiontest", $con); //upddate the database if( strlen($updatePassword) < 5) { mysql_query("UPDATE pensionbalance SET PIN='$updatePassword' WHERE first_name='Chiemezie'"); } // close the connection mysql_close($con); # #Write data to file. #**/ ############################################################################### ?>
Sponsor our Newsletter | Privacy Policy | Terms of Service