How can I search Linkedin via PHP?

I have a PHP script that opens http requests with CURL

: (it also accepts a header if needed)

   $c = curl_init();
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
if ($post_paramtrs) {
    curl_setopt($c, CURLOPT_POST, TRUE);
    curl_setopt($c, CURLOPT_POSTFIELDS, "var1=bla&" . $post_paramtrs);
}
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:33.0) Gecko/20100101 Firefox/33.0");
curl_setopt($c, CURLOPT_COOKIEJAR, $dirname . 'cookief.txt');
curl_setopt($c, CURLOPT_COOKIEFILE, $dirname . 'cookief.txt');
curl_setopt($c, CURLOPT_MAXREDIRS, 10);
$follow_allowed = (ini_get('open_basedir') || ini_get('safe_mode')) ? false : true;
if ($follow_allowed) {
    curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
}
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 9);
curl_setopt($c, CURLOPT_REFERER, $url);
curl_setopt($c, CURLOPT_TIMEOUT, 60);
curl_setopt($c, CURLOPT_AUTOREFERER, true);
curl_setopt($c, CURLOPT_ENCODING, 'gzip,deflate');
$data = curl_exec($c);
$status = curl_getinfo($c);
curl_close($c);
      

Run codeHide result


It works. Now I want to get a linkedin search result. Here is the page you can search for. As you can see it is sending an ajax request to get the data. For example, if you want to find Peter

, it sends this request:

https://www.linkedin.com/voyager/api/typeahead/hits?q=blended&query=Peter

      

But when you open it manually, it fails and throws this error:

CSRF error.

This means that I have to pass this token along with the request:

enter image description here


What's my question? How can I find this token? Noted that it is not in the DOM. Will it be generated by JS? Anyway, do you have any hints for me?

+3
javascript security php curl


source to share


No one has answered this question yet

See similar questions:

98
how to get cookies from php curl into variable
27
How can I send cookie using PHP curl in addition to CURLOPT_COOKIEFILE?

or similar:

4270
Link. What does this symbol mean in PHP?
1065
Link. What does this error mean in PHP?
606
PHP syntax / syntax errors; and how to solve them?
213
Why put CSRF tokens in cookies so often?
117
How can I find where I will be redirected using cURL?
71
Where to store JWT in the browser? How to protect against CSRF?
27
anti-CSRF token and Javascript
3
Is my CSRF protection method protected?
1
csurf: How can we pass the csrf token to the client without inserting it into the template view?
0
PHP cURL - Request execution failed due to missing or invalid XSRF token



All Articles
Loading...
X
Show
Funny
Dev
Pics