# Flash frontend for php code

**URL:** <https://forum.kirupa.com/t/flash-frontend-for-php-code/127112>\
**Category:** Uncategorized\
**Created:** [October 30, 2004, 2:40pm UTC](https://forum.kirupa.com/t/flash-frontend-for-php-code/127112 "2004-10-30T14:40:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gf05856](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@gf05856](https://forum.kirupa.com/u/gf05856)\
**Post date:** [October 30, 2004, 2:40pm UTC](https://forum.kirupa.com/t/flash-frontend-for-php-code/127112/1 "2004-10-30T14:40:04Z")

</div>

Dear,

Would anyone happen to have some frontend flash file to read and activate the php code below?

Do not know how to start with this, can anyone give me a push in the right direction?

The below code is to send an SMS (short message service via GSM) from a website. I would like to do this from flash.

\<?php  
/\*  
################################################################################

# Filename: sms\_api.php

# Create date: 09.01.2004.

# Last update: 10.04.2004.

# Project: WSW - [Netsector.net](http://Netsector.net)

# Description: Simple CLICKATELL SMS API using fopen functions or CURL PHP module

# 

# NOTE: PHP must have SSL support for maximum security of Yours

# CLICKATELL account. If PHP is not built with SSL support, change $base\_s to

# “[http://api.clickatell.com/http" instead "[url=“https://api.clickatell.com/http”]https://api.clickatell.com/http](http://api.clickatell.com/http)”.

# 

# For more information about CLICKATELL service visit [http://www.clickatell.com](http://www.clickatell.com/)

# 

# Copyright © 2004 Aleksandar Markovic \<[miki@netsector.net](mailto:miki@netsector.net)\>

# Copyright © 2003 - 2004 Netsector

###############################################################################  
\*/  
class sms {

/\* User Authentication \*/  
var $api\_id = “YOUR\_CLICKATELL\_API\_NUMBER”;  
var $user = “YOUR\_CLICKATELL\_USERNAME”;  
var $password = “YOUR\_CLICKATELL\_PASSWORD”;

/\* SMS Gateways URLs \*/  
var $base = “[http://api.clickatell.com/http](http://api.clickatell.com/http)”;  
var $base\_s = “[https://api.clickatell.com/http](https://api.clickatell.com/http)”;

/\* Define SMS balance limit \*/  
var $balace\_limit = 20;

/\* Gateway command sending method [curl|fopen] \*/  
var $sending\_method = “fopen”;

/\* Session variable \*/  
var $session;

/\* Class initialization \*/  
function sms () {  
$this-\>auth();  
}

/\* SMS gateway authentication \*/  
function auth() {  
$comm = sprintf ("%s/auth?api\_id=%s&user=%s&password=%s", $this-\>base\_s, $this-\>api\_id, $this-\>user, $this-\>password);  
$this-\>session = $this-\>\_parse\_auth ($this-\>\_execgw($comm));  
}

/\* Query SMS credis balance \*/  
function getbalance() {  
$comm = sprintf ("%s/getbalance?session\_id=%s", $this-\>base, $this-\>session);  
return $this-\>\_parse\_getbalance ($this-\>\_execgw($comm));  
}

/\* Send SMS message \*/  
function send($to=null, $from=null, $text=null) {

/\* Check SMS credits balance \*/  
if ($this-\>getbalance() \< $this-\>balace\_limit) {  
die (“You have reach the SMS credit limit!”);  
};

/\* Check SMS $text length \*/  
if (strlen ($text) \> 160) {  
die (“Your message is to long! (Current lenght=”.strlen ($text).")");  
}

/\* Check $to and $from is not empty \*/  
if (empty ($to)) {  
die (“You not specify destination address (TO)!”);  
}  
if (empty ($from)) {  
die (“You not specify source address (FROM)!”);  
}

/\* Reformat $to number \*/  
$cleanup\_chr = array ("+", " ", “(”, “)”, “\r”, "  
", "  
");  
$to = str\_replace($cleanup\_chr, “”, $to);

/\* Send SMS now \*/  
$comm = sprintf ("%s/sendmsg?session\_id=%s&to=%s&from=%s&text=%s", $this-\>base, $this-\>session, rawurlencode($to), rawurlencode($from), rawurlencode($text) );  
return $this-\>\_parse\_send ($this-\>\_execgw($comm));  
}

/\* PRIVATE FUNCTIONS \*/

/\* Execute gateway commands \*/  
function \_execgw($command) {  
if ($this-\>sending\_method == “curl”)  
return $this-\>\_curl($command);  
if ($this-\>sending\_method == “fopen”)  
return $this-\>\_fopen($command);  
die (“Unsupported sending method!”);  
}

/\* CURL sending method \*/  
function \_curl($command) {  
$this-\>\_chk\_curl();  
$ch = curl\_init ($command);  
curl\_setopt ($ch, CURLOPT\_HEADER, 0);  
curl\_setopt ($ch, CURLOPT\_RETURNTRANSFER,1);  
curl\_setopt ($ch, CURLOPT\_SSL\_VERIFYPEER,0);  
$result=curl\_exec ($ch);  
curl\_close ($ch);  
return $result;  
}

/\* fopen sending method \*/  
function \_fopen($command) {  
$result = ‘’;  
$handler = @fopen ($command, ‘r’);  
if ($handler) {  
while ($line = @fgets($handler,1024)) {  
$result .= $line;  
}  
fclose ($handler);  
return $result;  
} else {  
die (“Error while executing fopen sending method!\<br\>Please check does PHP have OpenSSL support and check does PHP version is greater than 4.3.0.”);  
}  
}

/\* Parse authentication command response text \*/  
function \_parse\_auth ($result) {  
$session = substr($result, 4);  
$code = substr($result, 0, 2);  
if ($code!=“OK”) {  
die (“Error in SMS authorization! ($result)”);  
}  
return $session;  
}

/\* Parse send command response text \*/  
function \_parse\_send ($result) {  
$code = substr($result, 0, 2);  
if ($code!=“ID”) {  
die (“Error sending SMS! ($result)”);  
} else {  
$code = “OK”;  
}  
return $code;  
}

/\* Parse getbalance command response text \*/  
function \_parse\_getbalance ($result) {  
$result = substr($result, 8);  
return (int)$result;  
}

/\* Check for CURL PHP module \*/  
function \_chk\_curl() {  
if (!extension\_loaded(‘curl’)) {  
die (“This SMS API class can not work without CURL PHP module! Try using fopen sending method.”);  
}  
}  
}

/\* Example \*/  
$mysms = new sms();  
//echo $mysms-\>session;  
//echo $mysms-\>getbalance();  
echo $mysms-\>send(“38160123”,“netsector”,“TEST MESSAGE”);

?\>
