mIRC Home    About    Download    Register    News    Help

Print Thread
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.

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.
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
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

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.

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
You don't need to +1 the content-length.

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.

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
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.
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...

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.,

Joined: Nov 2006
Posts: 143
X
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?

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
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.


Link Copied to Clipboard