Re: Help, I'm so close!!!
| From: | Marc Hanlon | Date: | Wed, 15 Aug 2001 21:56:15 +0000 |
| Subject: | Re: Help, I'm so close!!! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-62910@lists.php.net to get a copy of this message | ||
Brandon,
I was told of a better way of sending POSTs without using cURL and it allows
usernames and passwords to be used...
// Format of $authorization is username:password (for password protected
directories)
// Code can be easily modified to add input parameters for User-Agent,
Referer,
Cookie, Accept-Encoding or other required headers
function HTTPPost($host, $path, $dataToSend, $port = 80, $authorization =
"")
{
if(!($fp = fsockopen($host, $port)))
{
return "<b>From HTTPPost()</b><br>\n<b>Error:</b> Error
opening
network
socket.<br>\n";
}
socket_set_blocking($fp, TRUE);
fwrite($fp, "POST $path HTTP/1.0\r\n");
if($authorization != "") fwrite($fp, "Authorization: Basic " .
base64_encode($authorization) . "\r\n");
fwrite($fp, "Host: $host\r\n");
fwrite($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fwrite($fp, "Content-length: " . strlen($dataToSend) . "\r\n\r\n");
fwrite($fp, $dataToSend);
for($result = ""; !feof($fp); $result .= fread($fp, 1000000));
fclose($fp);
return $result;
}
Many thanks to Brad Jackson who provided this code to me.
Marc.
"Brandon Orther" <orther@webintellects.com> wrote in message
news:008901c125ab$f0242320$5a52a040@webintel...
Hello,
Using cURL:
I have been working for some time to get my PHP program to login to an
https site and now that it logs in I can't figure out how to do a post
to the site while I am logged in. After I use curl to login I do
another curl session to try and emulate a form post. But when I get the
results it is just the login page. Does anyone know how after my script
logs in to a site I can run another curl post while I am logged in?
Thank you,
--------------------------------------------
Brandon Orther
WebIntellects Design/Development Manager
brandon@webintellects.com
800-994-6364
www.webintellects.com
--------------------------------------------