Skip to content

Commit

Permalink
add del_cookie function
Browse files Browse the repository at this point in the history
  • Loading branch information
Zetao Yang authored and Zetao Yang committed Sep 14, 2017
1 parent c5b3a15 commit 6b98592
Showing 1 changed file with 55 additions and 11 deletions.
66 changes: 55 additions & 11 deletions core/requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,43 @@ public static function get_cookies($domain = '')
return empty($domain) ? self::$cookies : self::$domain_cookies[$domain];
}

/**
* 删除Cookie
*
* @param string $domain 不传则删除全局Cookie
* @return void
* @author seatle <seatle@foxmail.com>
* @created time :2017-08-03 18:06
*/
public static function del_cookie($key, $domain = '')
{
if (empty($key))
{
return false;
}

if (!empty($domain) && !isset(self::$domain_cookies[$domain]))
{
return false;
}

if (!empty($domain))
{
if (isset(self::$domain_cookies[$domain][$key]))
{
unset(self::$domain_cookies[$domain][$key]);
}
}
else
{
if (isset(self::$cookies[$key]))
{
unset(self::$cookies[$key]);
}
}
return true;
}

/**
* 删除Cookie
*
Expand All @@ -208,13 +245,16 @@ public static function del_cookies($domain = '')
{
return false;
}
if ( empty($domain))
if ( empty($domain) )
{
unset(self::$cookies);
self::$cookies = array();
}
else
{
unset(self::$domain_cookies[$domain]);
if (isset(self::$domain_cookies[$domain]))
{
unset(self::$domain_cookies[$domain]);
}
}
return true;
}
Expand Down Expand Up @@ -640,22 +680,26 @@ public static function request($url, $method = 'GET', $fields = array(), $files
if (!empty($fields))
{
// 不是上传文件的,用http_build_query, 能实现更好的兼容性,更小的请求数据包
if (is_array($fields) && empty($file_fields))
if ( empty($file_fields) )
{
$fields = http_build_query($fields);
// post方式
if ( is_array($fields) )
{
$fields = http_build_query($fields);
}
}
else
{
// 如果是json
if (!is_null($stance = json_decode($fields, true)))
{
$fields = json_encode(array_merge($stance, $file_fields));
}
else
// 有post数据
if ( is_array($fields) && !empty($fields) )
{
// 某些server可能会有问题
$fields = array_merge($fields, $file_fields);
}
else
{
$fields = $file_fields;
}
}
// 不能直接传数组,不知道是什么Bug,会非常慢
curl_setopt( self::$ch, CURLOPT_POSTFIELDS, $fields );
Expand Down

0 comments on commit 6b98592

Please # to comment.