file_get_contents post $cookie, how?
Posted: Fri Jul 16, 2010 11:56 am
Below code is works,
But if put cookie value into $cookie, the code will never works, WHY???
Code: Select all
<?
$data = array
(
'msg_author' => 'poster',
'msg_body' => 'gsd958gjsj sdj958fdsj',
'event' => 'comment',
'pid' => '15',
'submit' => 'OK',
);
function Post($url, $post = null)
{
$context = array();
if (is_array($post))
{
ksort($post);
$context['http'] = array
(
'method' => 'POST',
'header' => 'Cookie: 62be229b68f9a8202715cdd8c7092e31=63b33644fd6ed03214ed3887d7ead743; expires=Wed, 28-Jul-2010 13:53:37 GMT; path=/; cpg140_data=YToyOntzOjI6IklEIjtzOjMyOiI5NzMxMzFkOTJhZDU3MzExZTZmODMyZDlhMDRkNjZjNyI7czoyOiJhbSI7aToxO30%3D; expires=Fri, 13-Aug-2010 13:53:37 GMT; path=/;\r\n',
'content' => http_build_query($post, '', '&'),
);
}
return file_get_contents($url, false, stream_context_create($context));
}
echo Post('http://domain/post.php', $data);
?>Code: Select all
<?
$data = array
(
'msg_author' => 'poster',
'msg_body' => 'gsd958gjsj sdj958fdsj',
'event' => 'comment',
'pid' => '15',
'submit' => 'OK',
);
$cookie="Cookie: 62be229b68f9a8202715cdd8c7092e31=63b33644fd6ed03214ed3887d7ead743; expires=Wed, 28-Jul-2010 13:53:37 GMT; path=/; cpg140_data=YToyOntzOjI6IklEIjtzOjMyOiI5NzMxMzFkOTJhZDU3MzExZTZmODMyZDlhMDRkNjZjNyI7czoyOiJhbSI7aToxO30%3D; expires=Fri, 13-Aug-2010 13:53:37 GMT; path=/;\r\n";
function Post($url, $post = null)
{
$context = array();
if (is_array($post))
{
ksort($post);
$context['http'] = array
(
'method' => 'POST',
'header' => $cookie,
'content' => http_build_query($post, '', '&'),
);
}
return file_get_contents($url, false, stream_context_create($context));
}
echo Post('http://domain/post.php', $data);
?>