I set a cookie in http://sometwebsitename.com/newd/ like this:
setcookie("username", "jason", time()+36000, "/newd/");
I would like to use the cookie value while running a script in another folder http://sometwebsitename.com/checkcookie.php and not from http://sometwebsitename.com/newd/ which is where the cookie is actually set.
Lets say I use: echo $_COOKIE["username"];
It doesn't work because the cookie is set in /newd/ which I understand.
So, how I do I specifiy the path that needs to be used to check for the cookie value? I tried variations like:
echo $_COOKIE["/newd/username"];
echo $_COOKIE["../newd/username"];
echo $_COOKIE["http://sometwebsitename.com/newd/username"]; etc
but no luck.
What's the syntaxt for putting in the path name?
Would greatly appreciate any help. I have been breaking my head over this for 2 days. I am a PHP newb.
Thanks
syntax for COOKIE path
Moderator: General Moderators
You want it to be available within the whole domain.http://de2.php.net/setcookie wrote:path
[...]
If set to '/', the cookie will be available within the entire domain. If set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain. The default value is the current directory that the cookie is being set in.
Thanks Volka.
However, I am unable to set the cookie to be available for the whole domain. The cookie is being set by another application, and I have tried hacking that application to do so- it works, but has other unintended consequences and breaks that application. Should have mentioned that in my original post
I googled hard, read all kinds of manuals and forums, still no solution. Would appreciate any help.
However, I am unable to set the cookie to be available for the whole domain. The cookie is being set by another application, and I have tried hacking that application to do so- it works, but has other unintended consequences and breaks that application. Should have mentioned that in my original post
I googled hard, read all kinds of manuals and forums, still no solution. Would appreciate any help.
a) What other application?
WordPress 2.2
b) What did you change?
Put a plugin to make it store Username and User Password in the root / so that its available for other applications.
Activating plugin causes weird effects like inability to logout etc. It used to be ok during the previous version of WP.
Didn't do a complete test for other issues, so not sure what else is the problem.
c) Do you get error messages?
No error messages.
For these reasons, I thought of just accessing the cookies from another directory instead of usin plugins for WP. ALso, I plan to integrate other applications like a Forum, Photo Upload etc, and would rather go with first principles than a plugin for WP.
Thanks Volka!
WordPress 2.2
b) What did you change?
Put a plugin to make it store Username and User Password in the root / so that its available for other applications.
Activating plugin causes weird effects like inability to logout etc. It used to be ok during the previous version of WP.
Didn't do a complete test for other issues, so not sure what else is the problem.
c) Do you get error messages?
No error messages.
For these reasons, I thought of just accessing the cookies from another directory instead of usin plugins for WP. ALso, I plan to integrate other applications like a Forum, Photo Upload etc, and would rather go with first principles than a plugin for WP.
Thanks Volka!
preface: I'm unfamiliar with WordPress and just looked at the code.
There's a file wp-settings.php that defines two cookies affecting the cookie availabillity
If you replacebyall cookies set by WordPress should be available within the whole domain.
There's a file wp-settings.php that defines two cookies affecting the cookie availabillity
If you replace
Code: Select all
if ( !defined('COOKIEPATH') )
define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('home') . '/' ) );
if ( !defined('SITECOOKIEPATH') )
define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('siteurl') . '/' ) );Code: Select all
if ( !defined('COOKIEPATH') )
define('COOKIEPATH', '/' );
if ( !defined('SITECOOKIEPATH') )
define('SITECOOKIEPATH', '/' );Volka,
Thanks for your suggestions. Nice of you to take the time to read WordPress code.
I made the changes, and also made similar changes to the function:
if(!function_exists('wp_clearcookie'))
so that cookies are cleared on logout.
Then cleared all cookies in the site from my browser, and now seems to work fine.
Thanks for your suggestions. Nice of you to take the time to read WordPress code.
I made the changes, and also made similar changes to the function:
if(!function_exists('wp_clearcookie'))
so that cookies are cleared on logout.
Then cleared all cookies in the site from my browser, and now seems to work fine.