mIRC Homepage

Sockets (almost did it) but...

Posted By: flexer

Sockets (almost did it) but... - 09/09/03 01:37 PM

I am trying to post data from mirc to a website.
what I use is:
Code:
var %data = text= $+ %text

  sockwrite -n $sockname POST /post.php HTTP/1.0
  sockwrite -n $sockname Host: the-host.com
  sockwrite -n $sockname Content-Type: application/x-www-form-urlencoded
  sockwrite -n $sockname Content-Length: $len(%data)
  sockwrite -n $sockname
  sockwrite $sockname %data 

now everything works but the problem is that %text is from an editbox with options "multi return autovs vsbar" and when the users write in the box multiple lines (with enter) to the site is send only the first line frown
Please I am doing the script for 4 days and am almost done,.
Posted By: LocutusofBorg

Re: Sockets (almost did it) but... - 09/09/03 02:17 PM

loop through all the lines in your box, and sockwrite them one at a time.
Posted By: flexer

Re: Sockets (almost did it) but... - 09/09/03 03:16 PM

I don't understand.
you mean something like
sockwrite -n $sockname text=%line_1_from_textbox
sockwrite -n $sockname text=%line_2_from_textbox
sockwrite -n $sockname text=%line_3_from_textbox
sockwrite -n $sockname text=%line_4_from_textbox
confused
can you provide an example pls.
Posted By: Rich

Re: Sockets (almost did it) but... - 09/09/03 04:14 PM

Code:
  sockwrite -n $sockname POST /post.php HTTP/1.0
  sockwrite -n $sockname Host: the-host.com
  sockwrite -n $sockname Content-Type: application/x-www-form-urlencoded
  sockwrite -n $sockname Content-Length: $len(%data)
  sockwrite -n $sockname

  var %i = 0,%num = $did([i]<dialog>[/i],[i]<id>[/i]).lines
  while (%i < %num) {
    inc %i
    sockwrite -n $sockname $did([i]<dialog>[/i],[i]<id>[/i],%i).text
  }

This only works if the dialog is still open when you sockwrite this stuff.
If the dialog is supposed to close before that, you'll have to store the contents of the edit somewhere (like in a hidden custum window) and then send it from there.
Posted By: KoRn18

Re: Sockets (almost did it) but... - 09/09/03 09:10 PM

can i have ur php code plz?

(replied to wrong person)
Posted By: Online

Re: Sockets (almost did it) but... - 09/09/03 11:36 PM

Always send an encoded string to avoid parsing problems. Put this alias in your remotes,
Code:
alias urlencode {
  var %i = 1, %r
  while $mid($1-,%i,1) != $null {
    var %r = $+(%r,%,$base($asc($ifmatch),10,16)), %i = %i + 1
  } 
  return %r
}

and use: var %data = text= $+ $urlencode(%text)
Posted By: KingTomato

Re: Sockets (almost did it) but... - 10/09/03 02:47 AM

what about $didtok and make the delimiter a space character? It shouldnt interfere because mirc will kill two spaces.
Posted By: flexer

Re: Sockets (almost did it) but... - 10/09/03 02:37 PM

Here is what code I have done by myself which work perfectly smile
Code:
alias _multi {
var %i = 0,%num = $did(cutenews,$$2).lines
unset %r
while (%i < %num) {
inc %i
var %r = %r $+ & $+ $$1 $+ []= $+ $did(cutenews,$$2,%i).text
}
return %r
}

on *:sockopen:mysite:{


var %data = hello=1&username= $+ %tmp.username $+ $_multi(news_short,16) $+ &password= $+ %tmp.password $+ &news_title= $+ %tmp.news.title $+ $_multi(news_full,17)

  sockwrite -n $sockname POST / $+ %cn.path $+ /mirc2cn.php HTTP/1.0
  sockwrite -n $sockname Host: %cn.domain
  sockwrite -n $sockname Content-Type: application/x-www-form-urlencoded
  sockwrite -n $sockname Content-Length: $len(%data)
  sockwrite -n $sockname
  sockwrite -n $sockname %data

}

now In my PHP script I get an array like this
$news_full = array(
0 => line1
1 => line2
2 => line3
3 => line4
)
and with the php I can walk through the array $news_full and make only one string with all lines separated with <br>

Also I am doing this mirc script for my PHP script called CuteNews @ http://cutephp.com so you can post news at your site with just using your mIRC smile
Posted By: KingTomato

Re: Sockets (almost did it) but... - 10/09/03 03:23 PM

eww... GET passwords? >:\
Posted By: flexer

Re: Sockets (almost did it) but... - 10/09/03 06:21 PM

Quote:
eww... GET passwords? >:\
what do you mean ? everything is send through POST methot not GET.
Posted By: KingTomato

Re: Sockets (almost did it) but... - 10/09/03 06:36 PM

Arg...

Sorry, i noticed the first line and only took note of the &username= , &password=, so i assumed. I been really tired latly, so guess just didnt think it thorugh too well. My mistake >:D
Posted By: qwerty

Re: Sockets (almost did it) but... - 11/09/03 09:47 AM

How about this?
Code:
alias urlencode {
  bset -t &amp;a 1 $1- 
  tokenize 32 $bvar(&amp;a,1-) 
  var %a
  scid -r var % $+ b = $* , $eval(%a = %a $+ $iif($chr(%b) isalnum,$ifmatch,% $+ $base(%b,10,16,2)),0) 
  return %a
}
/scid -r allows you to "pass" $* to /var, /set or identifiers (something you can't do directly in a script) smile
© 2022 mIRC Discussion Forums