lib-mentarisms.php versi Beta

07Nov06

Maksudnya versi Beta itu bukan Beta pre-release tapi versi saya (kan nama saya Beta juga..) Masih acak adut, tapi yang penting SMS terkirim. Masalah perbaikan dan tambah fitur mah entar2 ajah..

<?php
/**
* lib-mentarisms.php
* include dulu file ini untuk dapat menggunakan class Mentarisms
* versi 0.01 Jumat, 23 Juni 2006
**/

define(“MENTARISMS_URL”, “http://www.klub-mentari.com/index.php&#8221;);
define(“MENTARISMS_LOGIN”, “http://www.klub-mentari.com/login.php&#8221;);
define(“MENTARISMS_KIRIM_SMS”, “http://www.klub-mentari.com/sms/xt_send_sms2.php&#8221;);
define(“MENTARISMS_REDIRECT”, “sms/send_sms2.php”);
define(“MENTARISMS_REFERER”, “http://www.klub-mentari.com/sms/send_sms2.php&#8221;);
define(“MENTARISMS_LOGOUT”, “http://www.klub-mentari.com/logout.php&#8221;);

define(“MENTARISMS_USERAGENT”, “lib-mentarisms.php Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)”);
define(“MENTARI_COOKIE_PATH”, “./”); // consider using /tmp or /var/tmp or other world-written directory

class Mentarisms {
var $username;
var $password;
var $mentari;

var $version;
var $created;
var $cookie_string;
var $cookie;
var $proxy_host;
var $proxy_auth;
var $sid;
var $is_login;
var $sent;
var $ch; // curl handle
var $status_log = array();
var $return_status = array();

function Mentarisms() {
$this->version = “0.01”;
$this->created = true;
if (!extension_loaded(‘curl’)) {
if (isset($_ENV[“NUMBER_OF_PROCESSORS”]) and ($_ENV[“NUMBER_OF_PROCESSORS”] > 1)) {
$this->created = false;
$a = array(
“action” => “constructing Mentarisms object”,
“status” => “failed”,
“message” => “lib-Mentarisms: Using a multithread server. Ensure php_curl.dll has been enabled (uncommented) in your php.ini.”
);
array_unshift($this->return_status, $a);

} else {
if (!dl(‘php_curl.dll’) && !dl(‘curl.so’)) {
$this->created = false;
$a = array(
“action” => “constructing Mentarisms object”,
“status” => “failed”,
“message” => “lib-Mentarisms: unable to load curl extension.”
);
array_unshift($this->return_status, $a);
}
}
}
if (!function_exists(“curl_setopt”)) {
$this->created = false;
$a = array(
“action” => “constructing Mentarisms object”,
“status” => “failed”,
“message” => “lib-Mentarisms: No curl.”
);
array_unshift($this->return_status, $a);
}
$this->username = $username;
$this->password = $password;
$this->proxy_host = “”;
$this->proxy_auth = “”;
$this->use_session = 2;
if ($this->created == true) {
$a = array(
“action” => “constructing Mentarisms object”,
“status” => “success”,
“message” => “lib-Mentarisms: Constructing completed.”
);
array_unshift($this->return_status, $a);
}
}

function setProxy($proxy_host, $proxy_user, $proxy_pass) {
if (strlen($this->proxy_host) > 0) {
$this->proxy_host = $proxy_host;
if (strlen($proxy_user) > 0 || strlen($proxy_pass) > 0) {
$this->proxy_auth = $proxy_user.”:”.$proxy_pass;
}
$a = array(
“action” => “set proxy”,
“status” => “success”,
“message” => “lib-Mentarisms: Proxy set.”
);
array_unshift($this->return_status, $a);
} else {
$a = array(
“action” => “set proxy”,
“status” => “failed”,
“message” => “lib-Mentarisms: no hostname supplied.”
);
array_unshift($this->return_status, $a);
}
}

function CURL_PROXY($cc) {

if (strlen($this->proxy_host) > 0) {
curl_setopt($cc, CURLOPT_PROXY, $this->proxy_host);
if (strlen($this->proxy_auth) > 0)
curl_setopt($cc, CURLOPT_PROXYUSERPWD, $this->proxy_auth);
}
}

function Login($username, $password){
$this->cookie = MENTARI_COOKIE_PATH.”mentari@cookie.txt”;
$this->username = $username;
$this->password = $password;

/* looking for sid */
$this->ch = curl_init();
curl_setopt($this->ch, CURLOPT_URL, MENTARISMS_URL);
$this->CURL_PROXY($this->ch);
curl_setopt($this->ch, CURLOPT_HEADER, 1); // baca header
curl_setopt($this->ch, CURLOPT_USERAGENT, MENTARISMS_USERAGENT);
curl_setopt($this->ch, CURLOPT_COOKIE, $this->cookie_string);
curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->cookie);
curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->cookie);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
$indexContent = curl_exec($this->ch);
$ereg_sid = ereg(“PHPSESSID\=([0-9a-z]+)”, $indexContent, $ketemu_sid);
$this->sid = $ketemu_sid[1];

/* Login */
curl_setopt($this->ch, CURLOPT_URL, MENTARISMS_LOGIN);
$this->CURL_PROXY($this->ch);
curl_setopt($this->ch, CURLOPT_POST, 1);
curl_setopt($this->ch, CURLOPT_USERAGENT, MENTARISMS_USERAGENT);
curl_setopt($this->ch, CURLOPT_COOKIE, $this->cookie_string);
curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->cookie.txt);
curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->cookie.txt);
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
$loginPost = “username=”.urlencode($this->username);
$loginPost .= “&password=”.urlencode($this->password);
$loginPost .= “&sid=”.urlencode($this->sid);
$loginPost .= “&redirect=”.urlencode(MENTARISMS_REDIRECT);
$loginPost .= “&login=Login”;
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $loginPost);
$loginContent = curl_exec($this->ch);
$ereg_mentari = ereg(“<span class\=\”genmed\”>\+([0-9a-z]+)”, $loginContent, $ketemu_mentari);
$this->mentari = $ketemu_mentari[1];
//$this->lihatErrorCurl($this->ch);
//curl_close($this->ch);
}

function kirimSms($recipient, $message) {
$this->recipient = $recipient;
$this->message = $message;
curl_setopt($this->ch, CURLOPT_URL, MENTARISMS_KIRIM_SMS);
$this->CURL_PROXY($this->ch);
curl_setopt ($this->ch, CURLOPT_POST, 1);
curl_setopt ($this->ch, CURLOPT_COOKIE, $this->cookie_string);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
$kirimPost = “recipient=”.urlencode($this->recipient);
$kirimPost .= “&message=”.urlencode($this->message);
$kirimPost .= “&jml_kar=125”;
$kirimPost .= “&username=”.urlencode($this->mentari);
$kirimPost .= “&user_id=&submit=”.urlencode(“Kirim SMS”);
curl_setopt ($this->ch, CURLOPT_POSTFIELDS, $kirimPost);
$kirimContent = curl_exec($this->ch);
$this->lihatErrorCurl($this->ch);
//curl_close($this->ch);
}

function terkirim() {
return $this->terkirim;
}

function lihatStatusLog() {
print implode(“<br>\n”, $this->status_log);
}

function lihatErrorCurl($ch) {
if (curl_errno($this->ch)) {
echo “cURL info:”. print_r(curl_getinfo($this->ch));
echo “<br>”;
echo “cURL error number:” .curl_errno($this->ch);
echo “<br>”;
echo “cURL error:” . curl_error($this->ch);
}
}
}
?>

Cara makenya:

<?php
/** test-libmentarisms.php
*/
include(“lib-mentarisms.php”);

$message = “lib-mentarisms send you sms at “.date(“d M Y H:i:s”).” my server time.”;

$mentari = new Mentarisms();
$mentari->Login(“username”, “password”);
$mentari->kirimSms(“628nomortujuan”, $message);

?>

Nah untuk urusan tampilannya terserah deh.. kreasi sendiri2.. kalo ada yang buat, saya dikasih tahu ya.. Thanks!



One Response to “lib-mentarisms.php versi Beta”

  1. wah udah jadi scriptnya, cobain ah… ^_^

    mas itu dibuat dulu ya includenya dengan nama lib-mentarisms.php
    baru kita buat tampilan untuk ngirimnya gitu ya?


Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s


%d blogger menyukai ini: