-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
31 lines (29 loc) · 942 Bytes
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
function save_cookie()
{
$filename = 'cookie.txt';
if (file_exists($filename) && filemtime($filename) > time() - 12 * 60 * 60)
return true;
$ch = curl_init('http://www.nic.ir/Just_Released');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$result = curl_exec($ch);
preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $result, $matches);
if (isset($matches[1][0])) {
parse_str($matches[1][0], $cookie);
if (!isset($cookie['IRNIC']))
return false;
$file = fopen($filename, "w") or die("Unable to open file!");
fwrite($file, $cookie['IRNIC']);
fclose($file);
return true;
}
return false;
}
function get_cookie()
{
$file = fopen("cookie.txt", "r") or die("Unable to open file!");
$cookie = fread($file, filesize("cookie.txt"));
fclose($file);
return !empty($cookie) ? $cookie : false;
}