Sunday, 25 August 2013

Error in my script, how do i correct it please?

Error in my script, how do i correct it please?

I included this code into my site to send sms to visitors but I get the
following error anytime I try: Fatal error: class 'sender' not found in
file. Please help will highly be appreciated. Please see code included
below.
include( "dbconnect.php" );
if ( isset( $_POST['mobile'] ) )
{
$mobile = $_POST['mobile'];
function createRandomPassword( )
{
$chars = "abcdefghkmnpqrstwxyz23456789";
srand((double)microtime() * 1000000);
$i = 0;
$pass = "";
if ( $i <= 7 )
{
$num = rand( ) % 33;
$tmp = substr( $chars, $num, 1 );
$pass = $pass.$tmp;
++$i;
}
}
return $pass;
}
$code = createRandomPassword( );
$sms = "SELECT * FROM sms_account WHERE id='1'";
if ( !( $smsresult = mysql_query( $sms ) ) )
{
exit( mysql_error( ) );
}
while ( $row = mysql_fetch_array( $smsresult ) )
{
$id = $row[id];
$account_id = $row[account_id];
$sms_password = $row[password];
$base_url = $row[base_url];
$sender_id = $row[sender_id];
$sms_status = $row[sms_status];
}
$query = "SELECT * FROM siteconfig WHERE id='1'";
if ( !( $result = mysql_query( $query ) ) )
{
exit( mysql_error( ) );
}
while ( $row = mysql_fetch_array( $result ) )
{
$weburl = $row[weburl];
$webfriendlyurl = $row[webfriendlyurl];
$webfriendlyname = $row[webfriendlyname];
}
$entry = trim( $_REQUEST['mobile'] );
$membermobile = preg_replace( "/\\s\\s+/ ", "", $entry );
$smsmessage = "Verification Code for your request on website:
\n".$code."\n\nSent Via -\n{$webfriendlyname}";
if ( $sms_status == "on" )
{
$ID = "{$account_id}";
$Pwd = "{$sms_password}";
$baseurl = "{$base_url}";
$VisPhNo = "233{$membermobile}";
$VisText = urlencode( "{$smsmessage}" );
$host = "{$baseurl}";
$port = "XXX";
$username = "{$ID}";
$password = "{$Pwd}";
$sender = "Xxxxx";
$message = "{$VisText}";
$tmobile = "{VisPhNo";
$msgtype = "0";
$dlr ="1";
$objSender= new Sender($host,$port,$username,$password,$sender,
$message,$tmobile,$msgtype,$dlr);
//$objSender->Sender();
$response=$objSender->Submit();
echo $response;
class Sender{
var $host;
var $port;
var $strUserName;
var $strPassword;
var $strSender;
var $strMessage;
var $strMobile;
var $strMessageType;
var $strDlr;
private function smsunicode($message){
$hex1='';
if (function_exists('iconv')) {
$latin = @iconv('UTF-8', 'ISO-8859-1', $message);
if (strcmp($latin, $message)) {
$arr = unpack('H*hex', @iconv('UTF-8', 'UCS-2BE', $message));
$hex1 = strtoupper($arr['hex']);
}
if($hex1 ==''){
$hex2='';
$hex='';
for ($i=0; $i < strlen($message); $i++){
$hex = dechex(ord($message[$i]));
$len =strlen($hex);
$add = 4 - $len; if($len< 4){
for($j=0;$j<$add;$j++){
$hex="0".$hex;
}
}
$hex2.=$hex;
}
return $hex2;
}
else{
return $hex1;
}
}
else{
print 'iconv Function Not Exists !';
}
}
//Constructor..
public function Sender
($host,$port,$username,$password,$sender,$message,$tmobile,$msgtype,$dlr){
$this->host=$host;
$this->port=$port;
$this->strUserName = $username;
$this->strPassword = $password;
$this->strSender= $sender;
$this->strMessage=$message; //URL Encode The Message..
$this->strMobile=$tmobile;
$this->strMessageType=$msgtype;
$this->strDlr=$dlr;
}
public function Submit(){
if($this->strMessageType=="2" ||
$this->strMessageType=="6") {
//Call The Function Of String To HEX.
$this->strMessage = $this->smsunicode($this->strMessage);
try{
//Smpp http Url to send sms.
$live_url="http://".$this->host.":".$this->port."/sendsms?username=".$this->strUserName."&password=".$this->strPassword."&type=".$this->strMessageType."&dlr=".$this->strDlr."&destination=".$this->strMobile."&source=".$this->strSender."&message=".$this->strMessage."";
//echo $live_url;exit();
$parse_url=file($live_url);
echo $parse_url[0];
}catch(Exception $e){
echo 'Message:' .$e->getMessage();
}
}
else
$this->strMessage=urlencode($this->strMessage);
try{
//Smpp http Url to send sms.
$live_url="http://".$this->host.":".$this->port."/sendsms?username=".$this->strUserName."&password=".$this->strPassword."&type=".$this->strMessageType."&dlr=".$this->strDlr."&destination=".$this->strMobile."&source=".$this->strSender."&message=".$this->strMessage."";
//echo $live_url;exit();
$parse_url=file($live_url);
echo $parse_url[0];
}
catch(Exception $e){
echo 'Message:' .$e->getMessage();
}
}
}
}
$check = "select mobile from tmp_req_mb where mobile = '{$mobile}';";
if ( !( $qry = mysql_query( $check ) ) )
{
exit( "Could not match data because ".mysql_error( ) );
}
$num_rows = mysql_num_rows( $qry );
if ( $num_rows != 0 )
{
if ( !( $sql_check = mysql_query( "update tmp_req_mb set
code='{$code}' where mobile='{$mobile}'" ) ) )
{
exit( mysql_error( ) );
}
if ( $sql_check == 1 )
{
echo "OK";
}
else
{
echo "ERROR";
}
}
else
{
if ( !( $sql_check = mysql_query( "insert into tmp_req_mb
(mobile,code) values('{$mobile}','{$code}')" ) ) )
{
exit( mysql_error( ) );
}
if ( $sql_check == 1 )
{
echo "OK";
}
else
{
echo "ERROR";
}
}
}

No comments:

Post a Comment