Based in this question , I was interested because some time ago I was doing a Twitter follower generator (followers exchange) and I managed ... but I found the answer to Inkeliz , and I'm trying, I tried hard not to ask for help but come on. We have the following code, which when giving a var_dump
before return
I get HTTP 200 OK
, ok so far so good, but it is returning me:
Notice: Undefined offset: 1 in C: \ wamp64 \ www \ test \ index.php on line 37
<?php
$cookie = '';
$csrf = '';
$url = 'https://twitter.com';
$getCSRFToken = curl_init();
curl_setopt_array($getCSRFToken, [
CURLOPT_URL => $url,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
CURLOPT_REFERER => $url,
CURLOPT_HEADER => true,
CURLOPT_HEADERFUNCTION => function($curl, $header) use (&$cookie){
if(strpos($header, 'Set-Cookie:') === 0){
if(preg_match('/Set-Cookie:\s?(.*?);/', $header, $matches)) {
$cookie .= $matches[1] . '; ';
}
}
return strlen($header);
}
]
);
$getCSRFToken = curl_exec($getCSRFToken);
preg_match('/name="csrf".*?value="(.*?)"/', $getCSRFToken, $matches);
$csrf = $matches[1];
if(preg_match('/name="csrf".*?value="(.*?)"/', $getCSRFToken, $matches)){
$csrf = $matches[1];
}
I took if
because if
was not working. What is the problem?
FIRST EDITION:
I removed the if
and changed the line:
preg_match('/name="csrf".*?value="(.*?)"/', $getCSRFToken, $matches);
To:
preg_match('/value="(.*?)" name="authenticity_token"/', $getCSRFToken, $matches);
It worked :)
Now comes another question, how do I use the value of return strlen($header);
to save Cookies
?