0
I saw some examples here on Stackoverflow, but I just couldn’t.
I need to format this string:
'personalization_id="v1_i8b1bAFy7m6K+j3TseNGDw=="'
If I use one $cookie = explode('=', $cookie);
she gets 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 gone, I need them to stay there, only = after the name of the cookie
scram.
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);
}
}
}
It can’t just be '$cookie = explode('="', $cookie);' ?
– AnthraxisBR
No he returns me only one = at the end and the remains of
cookies
will not be aarray
.– user94336
Are several cookies in the string ? they will always be the same ?
– AnthraxisBR
Yes they are various with different keys and values, another example:
fm=0
– user94336
But the names of the cookies will be the same correct ? I don’t think it can explode, I think you’ll have to use preg_math one for each cookie, but it will only work if the names are always
– AnthraxisBR
Aaa has to have a way.
twid="u=123456789"
this also removes = after the u– user94336
I edited the question the last code just run.
– user94336