note 103320 deleted from function.http-parse-cookie by sobak
| From: | sobak@php.net | Date: | Sun, 04 Dec 2016 07:21:52 +0000 |
| Subject: | note 103320 deleted from function.http-parse-cookie by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208059@lists.php.net to get a copy of this message | ||
Note Submitter: marcoigarapava at gmail dot com
----
Here's a good way to get cookies from a page and then resubimit the data to that page (or acess
any other page using the cookies gotten).
<?php
//SOME DATA TO POST
$postData = array
(
'user' => $login,
'pass' => $pass
);
//FIRST POST
$post1 = http_post_fields('http://example.com',
$postData);
//GET THE COOKIES STORED TO THE ARRAY $cookie
preg_match('/Set-Cookie: (.*)\b/', $post1, $cookie);
$cookie = (array) http_parse_cookie($cookie[1]);
$cookie = array( 'cookies' => $cookie["cookies"]);
//POST DATA NOW WITH THE COOKIE
$post2 = http_post_fields('http://example.com',
$postData, array(), $cookie);
?>