Jump to content

Help! To correction my curl post script


nicx

Recommended Posts

I was try to make a curl post script to http://www.sms-anda.com/indonesia/kirim/sms-gratis-indonesia.php but that not work. Please correction my script.

 //index.php  <?php

header("Content-type: text/html");
header("Cache-control: no-cache");
print("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
print("<html>");
echo "<head>
<title>Indosat FreeSMS</title>
</head>
<body bgcolor=\"#c7c7c7\">
";

include("isat.inc.php");
ini_set("implicit_flush", 1);

if($_SERVER["REQUEST_METHOD"] == "POST") {
  $_prosedur = new chawtSMS();
  $_prosedur->Initializing();
  if ($_prosedur->wraper($_POST["tujuan"], $_POST["pesan"] ))
     {
     print("<b>[info] SMS Terkirim</b>");
     }
     else {
     print("<b>[info] SMS Gagal Terkirim!!</b>");
     }
  $_prosedur->Logout();

}


echo "<form action=\"{$_SERVER["PHP_SELF"]}\" method=\"post\">";
echo "
 To:<br />
  <input type=\"text\" name=\"tujuan\" mini:hint=\"phone\" maxlenght=\"14\" value=\"628\"/><br />
 Text:<br />
  <textarea name=\"pesan\" maxlenght=\"90\"></textarea><br/>
  <input type=\"submit\" value=\"Send\"/><br />
 </form>
  ";


echo "
</body>
</html>";

?>

Link to comment
https://forums.phpfreaks.com/topic/125934-help-to-correction-my-curl-post-script/
Share on other sites

This the isat.inc.php

 <?php

if(!defined("CHAWT_SMS")) {
define("CHAWT_SMS", TRUE);
require("sistem.curl.php");

class chawtSMS
{
    var $errorstr;
    var $cookies = array();
    var $phoneno;
    var $logged = false;
    var $version;
    
    function ChawtSMS() {

        $this->version = "5.0 BETA";
        $this->logged = false;
    }
    
    function Initializing() {
        $this->cookies = array();
        $this->logged = false;
        
        if(FCurlGET("http://www.sms-anda.com/indonesia/kirim/sms-gratis-indonesia.php", $head, $body, array("Referer"=>"http://www.google.com"), true)) {
   if($this->cookies = $this->curi_cookies($head))
{
              return true;
} else {
$this->errorstr = "Couldn't get cookies array";
return false;
}
        } else {
echo 'Server Down!!<br/>';
return false;
}
    }
    
    function wraper($penerima, $pesan) {

/*      if(trim($user) == "" || trim($pwd) == ""){
print("<b>Blank Username or Password!!</b><br/>");
return false;      
}*/
   $count = strlen($pesan);
   $data = array('smsgratis' => '', 'penerima' => $penerima, 'pesan' => $pesan, 'submit' => 'kirim sms');

        FCurlPOST("http://www.sms-anda.com/indonesia/kirim/sms-gratis-indonesia.php", $head, $body, array("Referer"=>"http://sms-anda.com/indonesia/kirim/kirimsms.php", "Cookie"=> implode(";", $this->cookies)), $data);

$_tujuan = strlen($penerima);
         if($_tujuan > 2) {
   $code      =   substr($penerima, 0, 2)."";
   $penerima   =   substr($penerima, 2, $_tujuan+1)."";
   }
echo "<b>SMS to $code$penerima</b> ";
        $data = array();
        $data["penerima"]       =   $penerima;
        $data["pesan"]      =   $pesan;
        $data["kirim"]         =   "kirim sms";

        FCurlPOST("http://sms-anda.com/indonesia/kirim/kirimsms.php", $head, $body, array("Referer"=>"http://sms-anda.com/indonesia/kirim/kirimsms.php", "Cookie"=> implode(";", $this->cookies)), $data);

       if((strstr($body, "Success"))) {
           $this->logged = true;
print("<br/>Sukses coy!<br/>");
            return true;
        } else {
echo '<br/>Gagal <br/>';
return false;
      }
    }

function Logout() {

        if(!$this->logged)
return false;
       FCurlGET("http://sms-anda.com/indonesia/kirim/kirimsms.php", $head, $body, array("Referer"=>"http://sms-anda.com/indonesia/kirim/kirimsms.php", "Cookie"=>implode(";",$this->cookies)));
print("<br/><br/>");
      return true;
}
    function curi_cookies($s) {

        preg_match_all('/\nSet-Cookie: (.*?)/U', $s, $match, PREG_SET_ORDER);
        $r = array();
        foreach($match as $v) {
$r[] = $v[1];
}
return $r;
          }
   }
}

?>

And this the sistem.curl.php

<?php

if(!defined("FCURL_INCLUDED")) {
define("FCURL_INCLUDED", TRUE);

ini_set("default_socket_timeout", 60);

function FCurlGET($url, &$head, &$body, $header = array(), $follow_redirect = false)
{
    preg_match("/^http:\/\/([^\/]+)([^ \"\n\r\t<]*)/i", $url, $matches);
    $domain = $matches[1] ? $matches[1] : "";
    $location = $matches[2] ? $matches[2] : "/";
    if(!$domain) return false;
    
    $header = array_merge(
    array("Host"=>$domain, "User-Agent"=>"Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1)", "Accept"=>"text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap", "Connection"=>"Keep-Alive"),
    $header);
    /*
    $header = array_merge(
    array("Host"=>$domain),
    $header);
    */
    if(!($sock = fsockopen("{$domain}", 80, $errno, $errstr))) return false;
    //socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, 60);
    fputs($sock, "GET {$location} HTTP/1.0\r\n");
    foreach($header as $k => $v) {
        fputs($sock, "{$k}: {$v}\r\n");
    }
    fputs($sock, "\r\n");
    
    // Get First Head
    $head = "";
    while(!feof($sock)) {
        $s = fgets($sock, 4096);
        if($s == "\r\n") break;
        $head .= $s;
        if(($follow_redirect) && (substr($s, 0, strpos($s, ":")) == "Location")) {
            $r = trim(substr($s, strpos($s, ":")+1));
            if(substr($r, 0, strpos($r, ":")) == "http") {$r = $r;}
            elseif($r[0] == "/") {$r = "http://{$domain}{$r}";}
            else {
                $r = substr($url,0, strrpos("http://".$domain.$location, "/")).$r;
            }
            //print("Redirecting to.. {$r}");
            return FCurlGet($r, $head, $body, $header);
        }
    }
    
    // Then Body
    $body = "";
    while(!feof($sock)) {
        $body .= fread($sock, 4096);
    }
    
    fclose($sock);
    return true;
}

function FCurlPOST($url, &$head, &$body, $header = array(), $data = array())
{
    preg_match("/^http:\/\/([^\/]+)([^ \"\n\r\t<]*)/i", $url, $matches);
    $domain = $matches[1] ? $matches[1] : "";
    $location = $matches[2] ? $matches[2] : "/";
    
    if(!$domain) return false;
    $sdata = "";
    foreach($data as $k => $v) {
        $sdata .= $sdata ? "&" : "";
        $sdata .= urlencode("{$k}")."=".urlencode("{$v}");
    }
    
    if(!($sock = fsockopen("{$domain}", 80, $errno, $errstr))) return false;
    //socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, 60);
    fputs($sock, "POST {$location} HTTP/1.0\r\n");
    fputs($sock, "Host: {$domain}\r\n");
    fputs($sock, "Content-type: application/x-www-form-urlencoded\r\n");
    fputs($sock, "Content-length: " . strlen($sdata) . "\r\n");
    fputs($sock, "Accept: */*\r\n");
    foreach($header as $k => $v) {
        fputs($sock, "{$k}: {$v}\r\n");
    }
    fputs($sock, "\r\n");
    fputs($sock, "{$sdata}\r\n");
    fputs($sock, "\r\n");
    
    // Get First Head
    while($s = fgets($sock, 4096)) {
        if($s == "\r\n") break;
        $head .= $s;
    }
    
    // Then Body
    while(!feof($sock)) {
        $body .= fread($sock, 4096);
    }
    
    fclose($sock);
    return true;
}
}
?> 

please help to correction my curl post script because it not work.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.