Home » Php » php – Trim/select from a cookie file a specific value, read it and use it

php – Trim/select from a cookie file a specific value, read it and use it

Posted by: admin February 25, 2020 Leave a comment

Questions:

So i was trying to trim a specific value from my cookie file.
Cookie file:

# Netscape HTTP Cookie File
# https://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.

#HttpOnly_www.example.org   FALSE   /   FALSE   0   _nbuild_session a9b309f6b4f0ce81f759852bfbf45178
#HttpOnly_www.example.org   FALSE   /   TRUE    0   _nbuild_token   XLxBff5b%2B91%2FsuYM1Grt0CVkCGhX4Vsb83Yyb5SETiI%3D

I’m trying to get the _nbuild_token

XLxBff5b%2B91%2FsuYM1Grt0CVkCGhX4Vsb83Yyb5SETiI%3D

Which gets randomized because

curl_setopt($ch, CURLOPT_COOKIESESSION, 1);

This is how my function looks like

curl_setopt($ch, CURLOPT_URL, 'example.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, getcwd().'/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, getcwd().'/cookie.txt');
curl_setopt($ch, CURLOPT_POSTFIELDS, '$thetokenineed'):

I tried to trim but i find difficulties using that.
Is it even possible to trim from a cookie file?

How to&Answers: