mIRC Home    About    Download    Register    News    Help

Print Thread
Filling HTML's Form with Sockets ?! #235030 20/11/11 05:54 PM
Joined: Nov 2011
Posts: 52
E
eawedat Offline OP
Babel fish
OP Offline
Babel fish
E
Joined: Nov 2011
Posts: 52
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.

Re: Filling HTML's Form with Sockets ?! [Re: eawedat] #235055 21/11/11 01:12 PM
Joined: Jun 2003
Posts: 81
T
TRT Offline
Babel fish
Offline
Babel fish
T
Joined: Jun 2003
Posts: 81
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.

Last edited by TRT; 21/11/11 01:15 PM.
Re: Filling HTML's Form with Sockets ?! [Re: TRT] #235056 21/11/11 01:32 PM
Joined: Jan 2004
Posts: 1,274
L
Loki12583 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,274
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

Re: Filling HTML's Form with Sockets ?! [Re: Loki12583] #235060 21/11/11 04:17 PM
Joined: Nov 2011
Posts: 52
E
eawedat Offline OP
Babel fish
OP Offline
Babel fish
E
Joined: Nov 2011
Posts: 52
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.

Re: Filling HTML's Form with Sockets ?! [Re: eawedat] #235062 21/11/11 04:54 PM
Joined: Jan 2004
Posts: 1,274
L
Loki12583 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,274
You don't need to +1 the content-length.

Re: Filling HTML's Form with Sockets ?! [Re: Loki12583] #235063 21/11/11 04:56 PM
Joined: Nov 2011
Posts: 52
E
eawedat Offline OP
Babel fish
OP Offline
Babel fish
E
Joined: Nov 2011
Posts: 52
okay I removed it , but still not working.
the important thing is to let it work.

Re: Filling HTML's Form with Sockets ?! [Re: eawedat] #235066 21/11/11 05:58 PM
Joined: Jan 2004
Posts: 1,274
L
Loki12583 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,274
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)
}

Last edited by Loki12583; 21/11/11 06:00 PM.
Re: Filling HTML's Form with Sockets ?! [Re: Loki12583] #235067 21/11/11 06:20 PM
Joined: Nov 2011
Posts: 52
E
eawedat Offline OP
Babel fish
OP Offline
Babel fish
E
Joined: Nov 2011
Posts: 52
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...

Re: Filling HTML's Form with Sockets ?! [Re: eawedat] #235072 21/11/11 07:35 PM
Joined: Nov 2011
Posts: 52
E
eawedat Offline OP
Babel fish
OP Offline
Babel fish
E
Joined: Nov 2011
Posts: 52
by the way i tested it on iis server/asp it worked
but on apache/php no.,

Re: Filling HTML's Form with Sockets ?! [Re: eawedat] #235248 02/12/11 06:21 PM
Joined: Nov 2006
Posts: 143
X
xyzzy Offline
Vogon poet
Offline
Vogon poet
X
Joined: Nov 2006
Posts: 143
how can i close each socket only 1 time at the end of sockread?

Re: Filling HTML's Form with Sockets ?! [Re: xyzzy] #235250 02/12/11 07:09 PM
Joined: Jan 2004
Posts: 1,274
L
Loki12583 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,274
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.