cookie.class.php
class cookie
{
private $url;
private $conn;
private $user_agent;
private $debug=false;
private $cookie="cookies.txt_file";
public function __construct($url_input=""){
$this->conn=curl_init();
$this->setUrl($url_input);
$this->setUserAgent($this->getUserAgent());
}
public function __destruct(){
$this->conn=null;
$this->url="";
$this->user_agent="";
$this->cookie="";
}
public function post($post=false){
global $cookie_file;
$header = array(
"Connection: keep-alive",
"Accept: application/json, text/javascript, */*; q=0.01",
"Origin: https://twitter.com",
"X-Requested-With: XMLHttpRequest",
"User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36",
"Content-Type: application/x-www-form-urlencoded; charset=UTF-8",
"Referer: https://twitter.com/i/start/follow_interests?cid=-1",
"Accept-Encoding: gzip, deflate",
"Accept-Language: en-US,en;q=0.8,tr;q=0.6"
);
if($this->conn!=null){
curl_setopt($this->conn, CURLOPT_URL, $this->getUrl());
if($post){
curl_setopt($this->conn,CURLOPT_POSTFIELDS, $post);
curl_setopt($this->conn, CURLOPT_POST, 1);
}else{
curl_setopt($this->conn, CURLOPT_POST, 0);
}
curl_setopt($this->conn, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->conn, CURLOPT_COOKIEFILE, "../cookies/".$cookie_file);
curl_setopt($this->conn, CURLOPT_HEADER, 1);
curl_setopt($this->conn, CURLOPT_HTTPHEADER, $header);
curl_setopt($this->conn, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($this->conn, CURLOPT_RETURNTRANSFER, 1);
return curl_exec($this->conn);
}
return null;
}
public function get($post=false){
global $cookie_file;
if($this->conn!=null){
curl_setopt($this->conn, CURLOPT_URL, $this->getUrl());
if($post){
curl_setopt($this->conn,CURLOPT_POSTFIELDS, $post);
curl_setopt($this->conn, CURLOPT_POST, 1);
}else{
curl_setopt($this->conn, CURLOPT_POST, 0);
}
curl_setopt($this->conn, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->conn, CURLOPT_COOKIEFILE, "../cookies/".$cookie_file);
curl_setopt($this->conn, CURLOPT_HEADER, 1);
curl_setopt($this->conn, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($this->conn, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->conn, CURLOPT_USERAGENT, $this->user_agent);
return curl_exec($this->conn);
}
return null;
}
public function login($post=false){
global $cookie_file;
if($this->conn!=null){
curl_setopt($this->conn, CURLOPT_URL, $this->getUrl());
if($post){
curl_setopt($this->conn,CURLOPT_POSTFIELDS, $post);
curl_setopt($this->conn, CURLOPT_POST, 1);
}else{
curl_setopt($this->conn, CURLOPT_POST, 0);
}
curl_setopt($this->conn, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->conn, CURLOPT_COOKIEJAR, "../cookies/".$cookie_file);
curl_setopt($this->conn, CURLOPT_HEADER, 1);
curl_setopt($this->conn, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($this->conn, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->conn, CURLOPT_USERAGENT, $this->user_agent);
return curl_exec($this->conn);
}
return null;
}
public function closeConnection(){
if($this->conn!=null){
curl_close($this->conn);
}
}
public function getUserAgent(){
$agents = array(
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36'
);
return $agents[array_rand($agents)];
}
public function setUrl($url_input){
$this->url=$url_input;
}
public function getUrl(){
return $this->url;
}
public function setUserAgent($agent){
$this->user_agent=$agent;
}
public function getUserAgentVar(){
return $this->user_agent;
}
}
function random_string($length = 10)
{
$strs = array_merge(range("a", "z"), range("A", "Z"));
$strs = array_merge($strs, range("0", "9"));
$strs[] = "_";
shuffle($strs);
$strs = array_slice($strs, 0, $length);
return implode("", $strs);
}cookie.php$username = 'null';
$password = 'null';
$cookie_file = base64_encode(random_string(10)).".txt";
$bot=new cookie("https://twitter.com/");
$html=$bot->login();
preg_match('#value="([a-z-A-Z0-9]{0,}+)" name="authenticity_token"#siU', $html, $match);
$authenticity_token = $match[1];
$bot->setUrl("https://twitter.com/sessions");
$html=$bot->login("session[username_or_email]={$username}&session[password]={$password}&return_to_ssl=true&scribe_log=&redirect_after_login=%2F&authenticity_token={$authenticity_token}");Çıktı: