Skip to content

Instantly share code, notes, and snippets.

@namcoder
Created September 23, 2018 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save namcoder/522f714616cfec31bea8f9011a91f704 to your computer and use it in GitHub Desktop.
Save namcoder/522f714616cfec31bea8f9011a91f704 to your computer and use it in GitHub Desktop.
new way to login fshare
<?php
$filename = 'cookie.txt';
if (file_exists($filename)) {
if(time()-filemtime($filename) > 12 * 3600)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.fshare.vn/");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $result, $matches);
$cookies = array();
foreach($matches[1] as $item) {
parse_str($item, $cookie);
$cookies = array_merge($cookies, $cookie);
}
preg_match('/meta name=\"csrf-token\" content=\"(.*?)\"/', $result, $output);
$token = $output[1];
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, "https://www.fshare.vn/site/login");
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch2, CURLOPT_POSTFIELDS, "_csrf-app=".urlencode($token)."&LoginForm%5Bemail%5D=xxxxxxxxx%40gmail.com&LoginForm%5Bpassword%5D=xxxxxxxxx&LoginForm%5BrememberMe%5D=0");
curl_setopt($ch2, CURLOPT_POST, 1);
curl_setopt($ch2, CURLOPT_HEADER, 1);
$headers2 = array();
$headers2[] = "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36";
$headers2[] = "Cookie: fshare-app=".$cookies['fshare-app'];
curl_setopt($ch2, CURLOPT_HTTPHEADER, $headers2);
$result2 = curl_exec($ch2);
if (curl_errno($ch2)) {
echo 'Error:' . curl_error($ch2);
}
curl_close ($ch2);
preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $result2, $matches2);
$final_cookies = array();
foreach($matches2[1] as $item) {
parse_str($item, $cookie);
$final_cookies = array_merge($final_cookies, $cookie);
}
$myfile = fopen("cookie.txt", "w") or die("Unable to open file!");
$json->cookie = $final_cookies['fshare-app'];
$json->token = $token;
$final_json = json_encode($json);
fwrite($myfile,$final_json);
fclose($myfile);
}
}
@downloadvideo
Copy link

Cho mình hỏi file này có rồi thì code ntn nữa để get đc link à bạn ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment