nicx Posted July 11, 2008 Share Posted July 11, 2008 Hi,guys. I want to ask about how to make a curl post. I want to make curl post to website www.chawt.com that provide free sms. So,we can post login(user+pwd),recipient number,and text message and with report of sending the sms. How to create the curl sintax?? I was try but that failed,i have problem to source the url.Plz help me to write the sintax with the post form..Thank you... Quote Link to comment Share on other sites More sharing options...
nicx Posted July 11, 2008 Author Share Posted July 11, 2008 I want make like this site http://sms.kecoakwap.com/chawt/ can anyone write the script? Quote Link to comment Share on other sites More sharing options...
chronister Posted July 12, 2008 Share Posted July 12, 2008 can anyone write the script? The answer to that is most likely yes. But the real question is can YOU write the script? No one here wants to write things for you unless your in the freelance boards and will probably end up paying someone to do it. So, that being said...... Do you know any PHP? Have you googled CURL? Have you looked through the PHP manual? Do you just want someone to do it for you? The answers you give to these questions will pretty much dictate whether anyone will even attempt to HELP YOU. Not do it for you, but help you. Nate Quote Link to comment Share on other sites More sharing options...
nicx Posted July 12, 2008 Author Share Posted July 12, 2008 I was try bro.But it can work... Plz help me give the example sintax.Because i dont understand with using php manual/read tutorial. I need the right script to study it. Plz write the sintax Quote Link to comment Share on other sites More sharing options...
chronister Posted July 12, 2008 Share Posted July 12, 2008 Tell ya what.... you post what you have and I will take a look at it and see what I can do.... No offense, but I don't want to write it for ya... I am more than happy to help, but not write it for you. Quote Link to comment Share on other sites More sharing options...
nicx Posted July 12, 2008 Author Share Posted July 12, 2008 This my sintax: I was make like this: smslib.php <?php define("M3SMS_USERAGENT", "Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)"); define("M3SMS_URL", "http://www.chawt.com/index.php"); define("M3SMS_LOGIN", "http://www.chawt.com/index.php"); define("M3SMS_REDIRECT", "index.php"); define("M3SMS_FORMSMS", "http://www.chawt.com/index.php"); define("M3SMS_KIRIM_SMS", "http://www.chawt.com/index.php"); define("M3SMS_LOGOUT", "http://www.chawt.com"); define("m3_COOKIE_PATH", "./"); class M3SMS { var $username; var $password; var $m3; 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 $status; function M3SMS() { $this->version = "1.0"; $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 M3SMS object", "status" => "failed", "message" => "lib-M3SMS: Using a multithread server. Ensure php_curl.dll has been enabled (uncommented) in your php.ini." ); array_unshift($this->status_log, $a); } else { if (!dl('php_curl.dll') && !dl('curl.so')) { $this->created = false; $a = array( "action" => "constructing M3SMS object", "status" => "failed", "message" => "lib-M3SMS: unable to load curl extension." ); array_unshift($this->status_log, $a); } } } if (!function_exists("curl_setopt")) { $this->created = false; $a = array( "action" => "constructing M3SMS object", "status" => "failed", "message" => "lib-M3SMS: No curl." ); array_unshift($this->status_log, $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 M3SMS object", "status" => "success", "message" => "lib-M3SMS: Constructing completed." ); array_unshift($this->status_log, $a); } //$this->Login(); } 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-M3SMS: Proxy set." ); array_unshift($this->status_log, $a); } else { $a = array( "action" => "set proxy", "status" => "failed", "message" => "lib-M3SMS: no hostname supplied." ); array_unshift($this->status_log, $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 = m3_COOKIE_PATH."m3@cookie.txt"; $this->cookie = m3_COOKIE_PATH."m3@cookie.txt"; $this->username = $username; $this->password = $password; /* looking for sid */ $this->ch = curl_init(); curl_setopt($this->ch, CURLOPT_URL, M3SMS_URL); $this->CURL_PROXY($this->ch); curl_setopt($this->ch, CURLOPT_HEADER, 1); // baca header curl_setopt($this->ch, CURLOPT_USERAGENT, M3SMS_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, M3SMS_LOGIN); $this->CURL_PROXY($this->ch); curl_setopt($this->ch, CURLOPT_POST, 1); curl_setopt($this->ch, CURLOPT_USERAGENT, M3SMS_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("index.php"); $loginPost .= "&login=".urlencode("Log in"); curl_setopt($this->ch, CURLOPT_POSTFIELDS, $loginPost); $loginContent = curl_exec($this->ch); $this->lihatErrorCurl($this->ch); // curl_close($this->ch); } function kirimSms($recipient, $message) { // FORM SMS curl_setopt($this->ch, CURLOPT_URL, M3SMS_FORMSMS); curl_setopt($this->ch, CURLOPT_POST, 1); curl_setopt($this->ch, CURLOPT_USERAGENT, M3SMS_USERAGENT); curl_setopt($this->ch, CURLOPT_COOKIEJAR, $cookiefile); curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1); // langsung return curl_setopt($this->ch, CURLOPT_VERBOSE, 0); //awalnya 1 curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1); $formSMSContent = curl_exec ($this->ch); if(empty($this->m3)) { $ereg_m3 = ereg("<span class\=\"genmed\">\+([0-9a-z]+)", $formSMSContent, $ketemu_m3); $this->m3 = $ketemu_m3[1]; //echo "\$m3 = $ketemu_m3[1]<br />"; } // KIRIM SMS $this->recipient = $recipient; $this->txtMsg = $message; curl_setopt($this->ch, CURLOPT_URL, M3SMS_KIRIM_SMS); $this->CURL_PROXY($this->ch); curl_setopt ($this->ch, CURLOPT_POST, 1); curl_setopt($this->ch, CURLOPT_REFERER, M3SMS_FORMSMS); curl_setopt ($this->ch, CURLOPT_COOKIE, $this->cookie_string); curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1); $kirimPost = "recipient=".urlencode($this->recipient); $kirimPost .= "&txtMsg=".urlencode($this->txtMsg); $kirimPost .= "&jml_kar=160"; $kirimPost .= "&username=".urlencode($this->m3); $kirimPost .= "&user_id=&submit=".urlencode("Kirim SMS"); curl_setopt ($this->ch, CURLOPT_POSTFIELDS, $kirimPost); $kirimContent = curl_exec($this->ch); $infoKirim = curl_getinfo($this->ch); if($kirimContent) { if(ereg("Message Sent Successful", $kirimContent)) { $this->status = "SMS terkirim"; } elseif(ereg("SMS Gagal Terkirim", $kirimContent)) { $this->status = "over-limit"; } } else { if (empty($infoKirim['http_code'])) { $this->status = "No HTTP code was returned"; } else { $this->status = $infoKirim['http_code']; } } $this->lihatErrorCurl($this->ch); // curl_close($this->ch); } function terkirim() { return $this->terkirim; } function lihatStatusLog() { print implode("<br>\n", $this->status_log); } function status() { return $this->status; } 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); } } } ?> and the form.php <?php include("smslib.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>SMS | Chawt</title> </head> <body> "; echo "<p>"; if($_POST['message'] && $_POST['recipient']) { $m3 = new m3sms(); $m3->Login($_POST['username'], $_POST['password']); $m3->kirimSms($_POST['recipient'], $_POST['message']); echo "<br/><b>[iNFO] ".$m3->status()."</b><br/>"; } echo "<form action=\"{$_SERVER["PHP_SELF"]}\" method=\"post\"> User:<br/> <input type=\"text\" name=\"username\" value=\"\"/><br /> Pwd:<br/> <input type=\"password\" name=\"password\" value=\"\"/><br /> To:<br /> <input type=\"text\" name=\"recipient\" value=\"628\"/><br /> Text:<br /> <textarea name=\"message\" maxlenght=\"90\"></textarea><br/> <input type=\"submit\" value=\"Send\"/><br /> </form> "; print("</p>"); echo " </body> </html>"; ?> but this not work,something wrong with url setting in smslib.php can you help to the simple curl post?? Please correction my url in define fuction on smslib.Thankz Quote Link to comment Share on other sites More sharing options...
nicx Posted July 12, 2008 Author Share Posted July 12, 2008 I dont know the right url for the define fuction cos i cant view the source of the website www.chawt.com because in soure all page shown index.php plz help for the url and the simple curl post script. Quote Link to comment Share on other sites More sharing options...
Third_Degree Posted July 12, 2008 Share Posted July 12, 2008 For simple curl posting: http://phpgfx.com/tutorials/?action=read&id=32 Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 12, 2008 Share Posted July 12, 2008 I suggest you grab the live HTTP headers extension for firefox. It'll show you exactly what's being send to the server when you make the request yourself, so you'll be able to reproduce that with your cURL request. Quote Link to comment Share on other sites More sharing options...
Third_Degree Posted July 12, 2008 Share Posted July 12, 2008 I suggest you grab the live HTTP headers extension for firefox. It'll show you exactly what's being send to the server when you make the request yourself, so you'll be able to reproduce that with your cURL request. HTTP requests can get confusing and possibly detrimental to you code if you has never used them before, especially posts. If you are going to look at HTTP requests though, you might as well use sockets. Quote Link to comment Share on other sites More sharing options...
nicx Posted July 12, 2008 Author Share Posted July 12, 2008 I suggest you grab the live HTTP headers extension for firefox. It'll show you exactly what's being send to the server when you make the request yourself, so you'll be able to reproduce that with your cURL request. please help me with correction for my script or you can make a script like mine but with simple sintax? And can work to www.chawt.Com plz write the sintag. I want make like http://sms.kecoakwap.com/chawt/ and my problem is in sett the right url Quote Link to comment Share on other sites More sharing options...
nicx Posted July 12, 2008 Author Share Posted July 12, 2008 I suggest you grab the live HTTP headers extension for firefox. It'll show you exactly what's being send to the server when you make the request yourself, so you'll be able to reproduce that with your cURL request. i was show the source with firefox but that web using one page index.php to login n send sms. And the url only shown index.php in the source. *confuse Quote Link to comment Share on other sites More sharing options...
nicx Posted July 12, 2008 Author Share Posted July 12, 2008 For simple curl posting: http://phpgfx.com/tutorials/?action=read&id=32 using your tutorial,can you give an example for make curl post to chawt.com and make sms sending success?? Please help me with the sintax @all Quote Link to comment Share on other sites More sharing options...
nicx Posted July 12, 2008 Author Share Posted July 12, 2008 Mr.Where are you? Help me please Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 12, 2008 Share Posted July 12, 2008 As has been mentioned, we're not here to write things for you for free. Quote Link to comment Share on other sites More sharing options...
nicx Posted July 13, 2008 Author Share Posted July 13, 2008 As has been mentioned, we're not here to write things for you for free. whats? You want me to pay you? Please i'm only want to study. You're a php guru is money important to you?! Please help me with free Quote Link to comment Share on other sites More sharing options...
nicx Posted July 13, 2008 Author Share Posted July 13, 2008 As has been mentioned, we're not here to write things for you for free. whats? You want me to pay you? Please i'm only want to study. You're a php guru is money important to you?! Please help me with free Quote Link to comment Share on other sites More sharing options...
chronister Posted July 13, 2008 Share Posted July 13, 2008 WE ARE NOT GOING TO MAKE YOUR SCRIPT WORK FOR YOU, We will help you make it work. So, with your script that you already have.... what is it doing / not doing and what are you expecting. You have a bunch of code there already, so where is it going wrong? You need to do some basic troubleshooting and determine where the script is screwing up at. What errors are you getting? You just don't seem to want to try for yourself. You want someone to do it for you and we are NOT going to do that. We are here to help you learn not to do it for you. P.S. Yes, money is more important than your learning. I am pretty poor in every sense of the word... so if you want someone to write it for you then head to the freelance forum, or PM me and we will discuss my rates. Quote Link to comment Share on other sites More sharing options...
nicx Posted July 13, 2008 Author Share Posted July 13, 2008 I was write my script on page 1. Please help me to make it work! But you not help me. Im only want to know how to make it work,with the simple tag another my tag. Quote Link to comment Share on other sites More sharing options...
chronister Posted July 13, 2008 Share Posted July 13, 2008 If you don't HELP with this, I will ignore this thread and may even request it be closed.... So, with your script that you already have.... what is it doing / not doing and what are you expecting. You have a bunch of code there already, so where is it going wrong? You need to do some basic troubleshooting and determine where the script is screwing up at. What errors are you getting? I cannot take your code and run it on my server as it is calling classes and shit that your not posting here... WHAT ERRORS ARE YOU GETTING????? WHAT IS THE SCRIPT DOING vs WHAT YOUR EXPECTING IT TO DO?? You can't just post a bunch of code and give no details and expect us folks to freaking guess as to why it isn't working.... The best answer I can give you right now as to why it isn't working is that something is wrong with it... I can't begin to speculate what that might be unless you give more freaking information. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.