Welcome to WebmasterWorld Guest from 54.167.177.207

Forum Moderators: coopster & jatar k

cookies not working in wordpress

   
10:59 am on Nov 2, 2010 (gmt 0)

5+ Year Member



I am having difficult time handling cookies on a wordpress theme I am developing.

The site needs to drop a cookie on visitor computer so we know that the visitor has opted-in. after then we have to check that cookie value to be 1990 (eg) and then show the membership contents.

I know we can do this by using wp login system too, but for some reasons we do not want to use it. I have to do it thru cookie system so the user doesn't have to login everytime they visit.

I tried adding cookie with path/domains and without it too, but both do not work properly. sometimes it writes the cookie and does not read. sometimes it reads the old cookie.

please please help.

Thanks
3:38 pm on Nov 2, 2010 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Most likely you are setting an invalid date string, so it's defaulting to a session cookie? Let's see the code of how you set the cookie.
6:11 pm on Nov 2, 2010 (gmt 0)

5+ Year Member



Yeah I know I am doing something wrong. here is the code. I am using to set the cookie and retrieve the cookie in wordpress theme


$cookie_expiry=time()+60*60*24*30;
setcookie("OptPressSqueeze","1990", $cookie_expiry);


retrieving this cookie
echo $_COOKIE['OptPressSqueeze'];


I read somewhere that cookies work with path and domains only in WordPress and WP doesn't allow the cookies to work without path and domain. I tried that way also, but no luck.

thanks
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month