
![]() |
Boss
In my last post you've said
"Problems with the code, issues with elements of it that you want to go over... language discussion, understanding more of the concepts behind it? This is the place." So, now I have a problem with code. I want to send a message on tagworld with curl, but there's a problem. Here's my code (I can login and everything else): //Message form $msg['__EVENTTARGET'] = 'ctl00$ctl00$phBodyRight$phBodyRight$btnSend'; $msg['__EVENTARGUMENT'] = ''; $msg['__VIEWSTATE'] = $viewstate; $msg['chooseuserradio'] = '1'; $msg['ctl00$ctl00$phBodyRight$phBodyRight$lcSendTo'] = $to; $msg['ctl00$ctl00$phBodyRight$phBodyRight$tb_bmSubject'] = $subject; $msg['ctl00$ctl00$phBodyRight$phBodyRight$RTE1'] = $message; if(!empty($captcha)) { $msg['ctl00$ctl00$phBodyRight$phBodyRight$tbUserCode'] = $captcha; } //Send message curl_setopt($ch, CURLOPT_URL, "http://www.tagworld.com/$uname/SendMessage. aspx?recipient=$to");curl_setopt($ch, CURLOPT_REFERER, "http://www.tagworld.com/$uname/SendMessage. aspx?recipient=$to");curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/1.6"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $msg); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $page = curl_exec($ch); When I send the form above, it only sends a part of the form. I have tried with posting to file on my server and do the print_r of $_POST, but here's what I got then: POST: Array ( [Content-Type:_multipart/form-data;_boundary] => ----------------------------69a8b1ab6d4d ------------------------------69a8b1ab6d4d Content-Disposition: form-data; name="__EVENTTARGET" ctl00$ctl00$phBodyRight$phBodyRight$btnSend ------------------------------69a8b1ab6d4d Content-Disposition: form-data; name="__EVENTARGUMENT" ------------------------------69a8b1ab6d4d Content-Disposition: form-data; name="__VIEWSTATE" /wEPDwUKMTY1NDA1MTM0MA8WCB4LUmVmZXJyZXJVcmwFImh0dHA6Ly93d3cudGFnd29ybGQuY29tL2d1em9saXphYy8eB2NhcHRjaGFlHgdzdHJDb2RlZR4IaWRPZkNvZGVmFgJmD2QWAmYPZBYCAgMPZBYKAgEPZBYEZg9kFgRmD2QWAgIBDxYEHgRocmVmBStodHRwOi8vd3d3LnRhZ3dvcmxkLmNvbS9qb25rdXNhbi9JbmJveC5hc3B4Hglpbm5lcmh0bWwFAygyKWQCAQ8WBB8EBThodHRwOi8vd3d3LnRhZ3dvcmxkLmNvbS8tL1dvcmxkL1RyYWNraW5nLmFzcHg/YWZmX2lkPTkwNR4HVmlzaWJsZWhkAgIPDxYCHwZoZBYCAgEPFgQfBAUraHR0cDovL3d3dy50YWd3b3JsZC5jb20vam9ua3VzYW4vSW5ib3guYXNweB8FBQMoMilkAgIPZBYCAgIPZBYCZg8WAh4LXyFJdGVtQ291bnQCCWQCAw9kFgICAg9kFgJmDxYCHwcCAhYEAgEPZBYCZg9kFgJmDxYCHwcCBmQCAg9kFgJmD2QWAmYPFgIfB2ZkAggPZBYCZg9kFgQCBw8QZBAVARBTZWxlY3QgYSBsaXN0Li4uFQEBMBQrAwFnZGQCCw8PFgIfBmhkZAIKD2QWAgIGD2QWAmYPFgIfBmhkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYCBS5jdGwwMCRjdGwwMCRjdGwwMSRtZW51SGVhZGVyJGxvZ2luU3RhdHVzJGN0bDAxBS5jdGwwMCRjdGwwMCRjdGwwMSRtZW51SGVhZGVyJGxvZ2luU3RhdHVzJGN0bDAzXMKRiT4tr/RFCDc/1sdiyASCEeo= ------------------------------69a8b1ab6d4d Content-Disposition: form-data; name="chooseuserradio" 1 ------------------------------69a8b1ab6d4d Content-Disposition: form-data; name="ctl00$ctl00$phBodyRight$phBodyRight$lcSendTo" sendToUsername ------------------------------69a8b1ab6d4d Content-Disposition: form-data; name="ctl00$ctl00$phBodyRight$phBodyRight$tb_bmSubject" PHPsubject------------------------------69a8b1ab6d4d Content-Disposition: form-data; name="ctl00$ctl00$phBod ) Like you see, it only sends a part of the form and when it gets to the message part, it stops. Does anyone know where's the problem? perkiset
Hey Boss -
There was just a thread about this and crypt posted a reference to an article on posting a MP form with curl, it is all here: http://www.perkiset.org/forum/ php/multipartformdata_post_with_curl-t217.0.htmlhope that helps /p Boss
Perkiset, thanks for your reply, but I don't have that kind of problem. I can send multipart form, but curl won't send the whole form, just a part of it.
I tried with fsockopen, and it sends the whole form. However, I haven't been using fsockopen for logging into websites, so it would be nice if you could write an example of storing cookies with fsockopen. What I mean, I need to login with fsockopen and then go with this cookie to another page in my account. How to store cookies and use them with fsockopen? perkiset
Hey Jefe -
you don't "store" cookies locally with PHP- you simply receive and send them in the header. Storage of cookies is either automatic (if you send via the header) to a surfer, or it is manual using a library in JS like the "efficient local storage of cookies" code in the JS code repository here at the cache.When using either fsockopen or simply fopen, you need to create the header manually and send it in front of your content. Here is the header creation PHPfrom the webrequest class in the repository:if ($this->_method == 'GET') { $header = "GET $finalURL HTTP/1.1 "; $header .= "Host: {$this->Host} "; $header .= "User-Agent: Mozilla/5.0 ( Macintosh; U; PPCMacOS X; en)AppleWebKit/417.9 (KHTML, like Gecko) Safari/417.8 ";$header .= "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 "; $header .= "Accept-Language: en-us,en;q=0.5 "; $header .= "Accept-Encoding: "; $header .= "Accept-Charset: ISO-8859-1,utf-8:q=0.7,*;q=0.7 "; if ($cookieStr) { $header .= "Cookie: $cookieStr "; } $header .= "Connection: close "; $header .= "Content-Type: text/html "; $header .= "Content-Length: $requestLen "; } else { $header = "POST $finalURL HTTP/1.1 "; $header .= "Host: {$this->Host} "; $header .= "User-Agent: Mozilla/5.0 ( Macintosh; U; PPCMacOS X; en)AppleWebKit/417.9 (KHTML, like Gecko) Safari/417.8 ";$header .= "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 "; $header .= "Accept-Language: en-us,en;q=0.5 "; $header .= "Accept-Encoding: "; $header .= "Accept-Charset: ISO-8859-1,utf-8:q=0.7,*;q=0.7 "; if ($cookieStr) { $header .= "Cookie: $cookieStr "; } $header .= "Connection: close "; $header .= "Content-Type: application/x-www-form-urlencoded "; $header .= "Content-Length: $requestLen "; $header .= "$postStr "; } the variable $cookieStr was created earlier in a little code snippet like this: $cookieStr = ''; $start = true; foreach($this->cookieList as $name=>$value) { if (!$start) { $cookieStr .= '; '; } $cookieStr .= "$name=$value"; $start = false; } ... the array is simply an associative array that holds onto string values. I ensure that they are encoded (if there are dicey characters) in the "set" portion of the class. As I mentioned, the entire class is available in the repository. /p Boss
Thanks for that. It's really helpful.
perkiset
No worries mate - spamho!
![]() /p crypt
I'm here to save the day!!
![]() ![]() ![]() Ok first, check the response status... (after curl_exec()) $info = curl_getinfo($ch); echo $info->http_code ...should be 100, and that's due to an annoying default header in curl. add this to your options to work around it ![]() curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); ![]() ![]() perkiset
Yo dude... been a while! Nice to see you back!
crypt
Been busy making money
![]() ![]() |

Thread Categories

![]() |
![]() |
Best of The Cache Home |
![]() |
![]() |
Search The Cache |
- Ajax
- Apache & mod_rewrite
- BlackHat SEO & Web Stuff
- C/++/#, Pascal etc.
- Database Stuff
- General & Non-Technical Discussion
- General programming, learning to code
- Javascript Discussions & Code
- Linux Related
- Mac, iPhone & OS-X Stuff
- Miscellaneous
- MS Windows Related
- PERL & Python Related
- PHP: Questions & Discussion
- PHP: Techniques, Classes & Examples
- Regular Expressions
- Uncategorized Threads