I saw some examples here in StackOverflow , but I just could not.
I need to format this string:
'personalization_id="v1_i8b1bAFy7m6K+j3TseNGDw=="'
If I use a $cookie = explode('=', $cookie);
it looks like this:
0 => string 'personalization_id' (length=18)
1 => string '"v1_IQfbwu+xRVCTQaUk9sGfBQ' (length=26)
2 => string '' (length=0)
3 => string '"' (length=1)
Notice that the == in the end are gone, I need them to stay there, only = after the name of cookie
sum.
What is the solution?
My code:
if (preg_match_all('/^Set-Cookie: \s*([^;]*)/mi', $response, $matches)) {
foreach ($matches[1] as $cookie) {
$cookie = explode('=', $cookie);
var_dump($cookie);
}
}
Edited
function getCSRF() {
$request = curl_init();
curl_setopt_array($request, [
CURLOPT_URL => 'https://twitter.com/',
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HEADER => true,
CURLOPT_HTTPHEADER => [
'user-agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'
]
]
);
$response = curl_exec($request);
curl_close($request);
if (preg_match_all('/^Set-Cookie: \s*([^;]*)/mi', $response, $matches)) {
foreach ($matches[1] as $cookie) {
$cookie = explode('=', $cookie);
var_dump($cookie);
}
}
}