/    Sign up×
Community /Pin to ProfileBookmark

Newbie needs cookie help

I have a php app that is to set/update a cookie.
I am using
setcookie(“hdclimit”, $_GET[‘CLIMIT’], time() + (3600 * 24 * 364) + 5,”/”, “.v4.dir.com”);
to set the cookie.
and then
if (isset($_
COOKIE[hdclimit]))
{ print(“cookie has been set<br>”);
$default_climiter = $_COOKIE[hdclimit];
}
else { print(“The cookie wasn’t set”);$default_climiter = “10”;}

to determine whether or not the cookie has been set.

The first time I enter the web page, I receive the not set message and upon exiting I can find the cookie file in the C:Documents and SettingsusernameCookies directory.

The second time I enter the web page, I receive the cookie found message and the cookie value is used.

When I exit from the web page, the cookie is gone from the C:Documents and SettingsusernameCookies directory.

The 3rd time I enter the web page, I again receive the cookie not found message.

What causes this cookie to disappear on me. Is it not just supposed to update?

Should I be doing this using some other method?

TIA
D

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@insaneOct 27.2005 — insted of using the fomula for time(), try using the number.

it's 31536000 for 1 year

or, there's something wrong with your browser.

[i]-Insane[/i]

Ps.

use [code=php]
[code=php][/code]

tags
Copy linkTweet thisAlerts:
@moohueyauthorOct 27.2005 — Ok, tried that and I do have the php tags around the code, I just didn't include it in the post.

It is still doing the same thing. What would I look for under the browser issues. We are using ie explorer 6.

Could it be because I don't reset the value in the session. IE the cookie value is used to determine a setting in a drop down select that we want retained. The user can select a # of records to be displayed and we want the browser to retain that value for the next time they visit the page. Could the cookie be disapearin because they are resetting the value?

D
Copy linkTweet thisAlerts:
@chazzyOct 27.2005 — what he's asking for is for you to put your php code in php brackets for displaying in the forum. but either way can you post more of your code??

edit:

never mind, you can't check to see if a cookie is set or not on the same page that you set it. so what you got was the correct response. try to set your cookie like this:
[code=php]
setcookie("hdclimit", $_GET['CLIMIT'], time() + (3600 * 24 * 364) + 5)
[/code]
×

Success!

Help @moohuey 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.27,
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,
)...