-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]> | ||
* @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 | ||
* | ||
|
@@ -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; | ||
} | ||
|
@@ -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 ); | ||
|