Re: activate an external link thru crontab
| From: | Chris Shiflett | Date: | Tue, 21 Jan 2003 19:42:35 +0000 |
| Subject: | Re: activate an external link thru crontab | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-132502@lists.php.net to get a copy of this message | ||
--- Patrick <pafo@pafo.net> wrote:
> i want my page to send a report to a url, like a
> form. Is that possible thru php?
Sure. For the GET method, you can just use something like
fopen() to open the URL. For the POST method, you can try
something like this:
<base href="http://www.php.net/">
<?
$content = php_post("www.php.net", "/search.php",
"lang=en_US&pattern=curl&show=manual");
echo $content;
function php_post($host, $path, $data)
{
$http_response="";
$fp=fsockopen($host, 80);
fputs($fp, "POST $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-Type:
application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-Length: " .
strlen($data)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, "$data");
while(!feof($fp))
{
$http_response.=fgets($fp, 128);
}
fclose($fp);
list($http_headers, (http_content) =
explode("\r\n\r\n", $http_response);
return $http_content;
}
?>
Chris