I wondered if this functionality could be made:
Let's say our bot, through curl, logged in to the site and saved the cookie to a file. And when the page is updated, the bot will restart thereby overwriting the cookie file. And the question itself is whether it is possible to make so that if there are already cookies, it is not necessary to use the bot to re-enter the site. So he just opened it with the use of a long-time-recorded cookie.
Here is the bot that I write for twitter. And I want to integrate my goal here - if it is possible!
Thank you in advance!
Code:
<?php $ch = curl_init(); $sTarget = "https://twitter.com/login"; curl_setopt($ch, CURLOPT_URL, $sTarget); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($ch, CURLOPT_COOKIEFILE, "/twitter/cookie.txt"); curl_setopt($ch, CURLOPT_REFERER, "https://twitter.com/login"); $html = curl_exec($ch); preg_match('/<input type="hidden" value="([a-zA-Z0-9]*)" name="authenticity_token"\/>/', $html, $match); $authenticity_token = $match[1]; $username = "login"; $password = "pass"; # set post data $sPost = "session[username_or_email]=$username&session[password]=$password&return_to_ssl=true&scribe_log=&redirect_after_login=%2F&authenticity_token=$authenticity_token"; $sTarget = "https://twitter.com/sessions"; curl_setopt($ch, CURLOPT_URL, $sTarget); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $sPost); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded")); curl_exec($ch); curl_close($ch); ?>