Page 1 of 1
Sending a POST
Posted: Sat Jun 04, 2005 4:53 pm
by Odinian
Is there any way using only PHP to send a post command with certain variables?
Basically, I want to set several variables and send them as POST data.
So I can define something as $postvar_username, do something like post_to("url"). Then, at that URL, I would like to be able to use $_POST['username'], and get the value from the previous page.
Thanks for all help in advance!
Posted: Sat Jun 04, 2005 5:14 pm
by Ambush Commander
For the PHP library, see
cURL
Simpletest, however, contains a
scriptable browser suite that lets you do stuff like:
Code: Select all
$browser = &new SimpleBrowser();
$browser->get('http://my-site.com/register.php');
$browser->setField('email', 'me@here');
$browser->setField('password', 'Secret');
$browser->clickSubmit('Register');
Which is a lot easier to use than cURL (the standard response you'd get).
Posted: Sat Jun 04, 2005 7:12 pm
by Jim_Bo
Hi,
Maybe send it in the url as a variable and use GET on the next page
hth
Posted: Sat Jun 04, 2005 8:42 pm
by Ambush Commander
He wants to use POST, not GET. If you wanted to use POST without any external libraries, he'd end up opening up the socket himself and manually compiling the HTTP request data (very messy).
Posted: Sat Jun 04, 2005 9:05 pm
by Jim_Bo
Hi,
True, but GET will acheive what he wants ..
Just a thought for him thats was all.
Posted: Sat Jun 04, 2005 9:08 pm
by Ambush Commander
Then, at that URL, I would like to be able to use $_POST['username'], and get the value from the previous page.
Hmm... I must have missed that.
Posted: Sat Jun 04, 2005 11:38 pm
by Drachlen
Code: Select all
<BODY>
<FORM METHOD="POST" ACTION="postto.php" ID="postform">
<INPUT TYPE="HIDDEN" NAME="username" VALUE="Billybob">
</FORM>
</BODY>
<SCRIPT>
document.getElementById("postform").submit();
</SCRIPT>
This might be what you're looking for. One issue though, If you intend to pass a variable named "submit" it's going to get confused and break. So if whatever you're posting to requires that variable to be passed, It will fail and require an alternative:
Code: Select all
$variables = "username=Billybob";
$variables .= "&submit=Submit";
$socket = fsockopen("website.com",80);
fputs($socket,"POST /path/file.php HTTP/1.1\r\n");
fputs($socket,"Referer: Intarweb\r\n");
fputs($socket,"Host: Host\r\n");
fputs($socket,"Accept: text/html\r\n");
fputs($socket,"User-Agent: Intarweb Browser/1.0\r\n");
fputs($socket,"Content-type: application/x-www-form-urlencoded\r\n");
fputs($socket,"Content-length: ".strlen($variables)."\r\n");
fputs($socket,"Connection: Close\r\n");
fputs($socket,"\r\n");
fputs($socket,$variables."\r\n");
while(!feof($socket)){
$a = fgets($socket,256);
if ($a){
echo $a."<br>";
}
}