Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UserAdminV2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
庄欣
UserAdminV2
Commits
5a0a230b
Commit
5a0a230b
authored
Jun 15, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added ability to create cookies using properties.
parent
afd00260
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
95 additions
and
15 deletions
+95
-15
system/cookie.php
+95
-15
No files found.
system/cookie.php
View file @
5a0a230b
...
...
@@ -3,47 +3,127 @@
class
Cookie
{
/**
* The cookie name.
*
* @var string
*/
public
$name
;
/**
* The cookie value.
*
* @var mixed
*/
public
$value
;
/**
* The number of minutes the cookie should live.
*
* @var int
*/
public
$lifetime
=
0
;
/**
* The path for which the cookie is available.
*
* @var string
*/
public
$path
=
'/'
;
/**
* The domain for which the cookie is available.
*
* @var string
*/
public
$domain
=
null
;
/**
* Indicates if the cookie should only be sent over HTTPS.
*
* @var bool
*/
public
$secure
=
false
;
/**
* Create a new Cookie instance.
*
* @param string $name
* @return void
*/
public
function
__construct
(
$name
,
$value
=
null
)
{
$this
->
name
=
$name
;
$this
->
value
=
$value
;
}
/**
* Create a new Cookie instance.
*
* @param string $name
* @return Cookie
*/
public
static
function
make
(
$name
,
$value
=
null
)
{
return
new
static
(
$name
,
$value
);
}
/**
* Send the current cookie instance to the user's machine.
*
* @return bool
*/
public
function
send
()
{
if
(
is_null
(
$this
->
name
))
{
throw
new
\Exception
(
"Error sending cookie. The cookie does not have a name."
);
}
return
static
::
put
(
$this
->
name
,
$this
->
value
,
$this
->
lifetime
,
$this
->
path
,
$this
->
domain
,
$this
->
secure
);
}
/**
* Determine if a cookie exists.
*
* @param string $
key
* @param string $
name
* @return bool
*/
public
static
function
has
(
$
key
)
public
static
function
has
(
$
name
)
{
return
(
!
is_null
(
static
::
get
(
$
key
)));
return
(
!
is_null
(
static
::
get
(
$
name
)));
}
/**
* Get the value of a cookie.
*
* @param string $
key
* @param string $
name
* @param mixed $default
* @return string
*/
public
static
function
get
(
$
key
,
$default
=
null
)
public
static
function
get
(
$
name
,
$default
=
null
)
{
return
(
array_key_exists
(
$
key
,
$_COOKIE
))
?
$_COOKIE
[
$key
]
:
$default
;
return
(
array_key_exists
(
$
name
,
$_COOKIE
))
?
$_COOKIE
[
$name
]
:
$default
;
}
/**
* Set a "permanent" cookie. The cookie will last 5 years.
*
* @param string $
key
* @param string $
name
* @param string $value
* @param string $path
* @param string $domain
* @param bool $secure
* @return bool
*/
public
static
function
forever
(
$
key
,
$value
,
$path
=
'/'
,
$domain
=
null
,
$secure
=
false
)
public
static
function
forever
(
$
name
,
$value
,
$path
=
'/'
,
$domain
=
null
,
$secure
=
false
)
{
return
static
::
put
(
$
key
,
$value
,
2628000
,
$path
,
$domain
,
$secure
);
return
static
::
put
(
$
name
,
$value
,
2628000
,
$path
,
$domain
,
$secure
);
}
/**
* Set the value of a cookie.
*
* @param string $
key
* @param string $
name
* @param string $value
* @param int $minutes
* @param string $path
...
...
@@ -51,23 +131,23 @@ class Cookie {
* @param bool $secure
* @return bool
*/
public
static
function
put
(
$
key
,
$value
,
$minutes
=
0
,
$path
=
'/'
,
$domain
=
null
,
$secure
=
false
)
public
static
function
put
(
$
name
,
$value
,
$minutes
=
0
,
$path
=
'/'
,
$domain
=
null
,
$secure
=
false
)
{
if
(
$minutes
<
0
)
{
unset
(
$_COOKIE
[
$
key
]);
unset
(
$_COOKIE
[
$
name
]);
}
return
setcookie
(
$
key
,
$value
,
(
$minutes
!=
0
)
?
time
()
+
(
$minutes
*
60
)
:
0
,
$path
,
$domain
,
$secure
);
return
setcookie
(
$
name
,
$value
,
(
$minutes
!=
0
)
?
time
()
+
(
$minutes
*
60
)
:
0
,
$path
,
$domain
,
$secure
);
}
/**
* Delete a cookie.
*
* @param string $
key
* @param string $
name
* @return bool
*/
public
static
function
forget
(
$
key
)
public
static
function
forget
(
$
name
)
{
return
static
::
put
(
$key
,
null
,
-
60
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment