1
Based in this question, I was interested because some time ago I was making a follower generator pro Twitter (exchange of followers) and I got... but I thought it was cool the response of Inkeliz, and I’m trying, I’ve done everything not to ask for help but come on. We have the following code, which when giving a var_dump
before the return
return me HTTP 200 OK
, OK so far so good, but 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 of the if
was not working. What’s the problem?
FIRST EDITION:
took the if
and changed the line:
preg_match('/name="csrf".*?value="(.*?)"/', $getCSRFToken, $matches);
To:
preg_match('/value="(.*?)" name="authenticity_token"/', $getCSRFToken, $matches);
Worked :)
Now comes another question, how I use the value of return strlen($header);
to save Cookies
?
The error is on this line
/name="csrf".*?value="(.*?)"/
swap for/value="(.*?)".*?name="csrf"/
– WillBB
It’s not, I wasn’t even going to test, but I’ll kk I’m sure it’s not there
– user76271
give a
var_dump
in$matches
before associating position 1 in$csrf
and check if there really is a position 1– Don't Panic
Returned to me
array (size=0)
, but the problem is on the line that @Willbb quoted– user76271
changed the value of
name="csrf"
forauthenticity_token
and it worked– user76271
but I had to come but data...
– user76271