mIRC Homepage

Filling HTML's Form with Sockets ?!

Posted By: eawedat

Filling HTML's Form with Sockets ?! - 20/11/11 05:54 PM

hey all,,

With this simple given HTML's source :

index.html
Php Code:

<html>
<head><title></title></head>
<body>
<form action="get.php" method="POST">

<input type="text" name="address">

<select name="numbers">
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
</select>

<input type="submit" value="submit">
</form>
</body>
</html>
 



get.php
Php Code:


<?php
echo $_POST["address"];
echo "<br />";
echo $_POST["numbers"];
?>




My idea is :
Php Code:

1)connect mIRC to index.html via Sockets
2)fill any data into the field "address"
3)choose any option from "numbers"
4)submit form.
5)getting results from get.php back into mIRC. "echo -a $result"
 



I could not do it because until now I have seen many examples of how to get results from servers/webpages via sockets!
BUT not how to submit a form!


Any simple example would be very appreciated!


thanks a lot.
Posted By: TRT

Re: Filling HTML's Form with Sockets ?! - 21/11/11 01:12 PM

These are the (additional) headers to sent when requesting get.php

Code:
POST /get.php HTTP/1.1
...
Content-Type: application/x-www-form-urlencoded
Content-Length: 21
address=x&numbers=one


You can easily find more details on the syntax (like when you want to send files) with a search engine.
Posted By: Loki12583

Re: Filling HTML's Form with Sockets ?! - 21/11/11 01:32 PM

Code:
POST /get.php HTTP/1.1
...
Content-Type: application/x-www-form-urlencoded
Content-Length: 21

address=x&numbers=one


You'll need a blank line after the header and before the data, use the following to send a blank line:
Code:
sockwrite -n $sockname
Posted By: eawedat

Re: Filling HTML's Form with Sockets ?! - 21/11/11 04:17 PM

hey ,
I did this but did not work with me :

Php Code:

alias swrite { sockopen webpage localhost 80 }

on *:sockopen:webpage:{
  var %ver1 address=world&age=24
  sockwrite -n $sockname POST /koko/formsend.php HTTP/1.1
  sockwrite -n $sockname Content-Type: application/x-www-form-urlencoded
  sockwrite -n $sockname Content-Length: $calc($len(%ver1) +1)
  sockwrite -n $sockname host: localhost
  sockwrite -n $sockname
  sockwrite -n $sockname %ver1
}

on *:sockread:webpage:{ 
  var %a
  sockread %a
  echo -a %a $+ $chr(15)
}
 



I attached the script & php/html files:

Files Here


thanks.
Posted By: Loki12583

Re: Filling HTML's Form with Sockets ?! - 21/11/11 04:54 PM

You don't need to +1 the content-length.
Posted By: eawedat

Re: Filling HTML's Form with Sockets ?! - 21/11/11 04:56 PM

okay I removed it , but still not working.
the important thing is to let it work.
Posted By: Loki12583

Re: Filling HTML's Form with Sockets ?! - 21/11/11 05:58 PM

I changed the host and POST lines to test with this site <http://www.posttestserver.com/> and removed the -n from the last sockwrite (although it did work with it present). Try debugging with $sockerr.

The following returns what it should from the website, so the mirc script is correct. Maybe something is wrong with your php, your server, or you're trying to communicate with it improperly.

Code:
alias swrite { sockopen webpage posttestserver.com 80 }

on *:sockopen:webpage:{
  var %ver1 address=world&age=24
  sockwrite -n $sockname POST /post.php?dump HTTP/1.1
  sockwrite -n $sockname Content-Type: application/x-www-form-urlencoded
  sockwrite -n $sockname Content-Length: $len(%ver1)
  sockwrite -n $sockname host: localhost
  sockwrite -n $sockname
  sockwrite $sockname %ver1
}

on *:sockread:webpage:{ 
  var %a
  sockread %a
  echo -a %a $+ $chr(15)
}
Posted By: eawedat

Re: Filling HTML's Form with Sockets ?! - 21/11/11 06:20 PM

Loki thanks for your help.

your code worked with me 100%.

but mine i do not know..
i wanted to mention that I also tested it on my machine , I have Apache Server -> Localhost ..

strange...
Posted By: eawedat

Re: Filling HTML's Form with Sockets ?! - 21/11/11 07:35 PM

by the way i tested it on iis server/asp it worked
but on apache/php no.,
Posted By: xyzzy

Re: Filling HTML's Form with Sockets ?! - 02/12/11 06:21 PM

how can i close each socket only 1 time at the end of sockread?
Posted By: Loki12583

Re: Filling HTML's Form with Sockets ?! - 02/12/11 07:09 PM

Well you can't close it multiple times, but add a Connection: close header in the sockwrite - the server should close the connection after everything has been read.
© 2021 mIRC Discussion Forums