/    Sign up×
Community /Pin to ProfileBookmark

Error Using Date function in PHP Cookie

Hi ! I have written a Cookie code , but I am getting an error . I want the cookie to store some data and date to be renewd every time the user visits my site

[CODE]

?php
//Creating cookies
if(isset($_COOKIE[“visit”])) {
$visit_count = $_COOKIE[‘visit’];
setcookie (“visit”, ++$visit_count, date()+(60*60*24*365));
echo “Number of Visits”;
echo ($_COOKIE[‘visit’]) +1;
}else{
setcookie (“visit”, time(), time()+(60*60*24*365));
}
?>

[/CODE]

The Output is as below ,

Warning: date() expects at least 1 parameter, 0 given in C:xampphtdocstrialcook.php on line 5

Warning: Cannot modify header information – headers already sent by (output started at C:xampphtdocstrialcook.php:5) in C:xampphtdocstrialcook.php on line 5

Number of Visits1228008728

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@ratcatemeNov 30.2008 — change date() to time()

and shouldn't
[code=php]setcookie ("visit", time(), time()+(60*60*24*365));[/code]
be more like
[code=php]setcookie ("visit", 1, time()+(60*60*24*365));[/code]
other wise it will say on the second visit they have been here like 1228012427 times?

Scott.
×

Success!

Help @arpit_vavadia spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...