/    Sign up×
Community /Pin to ProfileBookmark

Cookie Failure in Subdirectory

[url]http://sturents.com[/url]

On the front page the user selects a location with a link in the form:
[url]http://sturents.com/location[/url]
This is mod_rewritten to load index.php which grabs this location from the URI to get the search page setup for that location. Other links on the site go to more generic pages (such as /about and /news) and so I didn’t want to have to preserve the location URL because it would be lying to search engines.

So that a user can go back to the search page without selecting a location again I’m trying to store the location value in a cookie. When the /location page is accessed it sets a cookie:

[code=php]setcookie(“loc”,$site[‘loc’][‘title’],time()+3600,’/’);[/code]

On future page loads if no location is present in the URI it checks to see if this cookie is there. However on any page that doesn’t specifically set the cookie the cookie is not there – calling print_r($_COOKIES) gives an array of all the cookies on the site (such as username and password) but not the location cookie. There is no line of code in the whole site that specifically unsets the cookie so my only thought is that its a problem with the fact that the site thinks its in a sub-directory when it writes the cookie.

Any thoughts?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@Dave_LaneJul 12.2009 — Have you tried leaving off the last two parameters when calling setcookie()? You might also try setting the domain parameter to '.sturents.com' instead of '/' and see if any change occurs.

I don't see anything wrong with the params you're using in your setcookie() call, but maybe you're encountering some weird quirk/bug...

I'm assuming you're doing this, but I'll ask anyway (everyone forgets sometimes): are you ensuring that $site['loc']['title'] is set to a non-null value (or string length > 0) before calling setcookie()?

Good luck!
×

Success!

Help @Inferno_str1ke 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.20,
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,
)...