Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.