MyBB Community Forums

Full Version: Cookies in another directory
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have my forum located in the / directory and I'm making a file in the /app directory. I need to be able to grab the username of the user from the / directory.

Can someone help?
If I'm not mistaken cookies can be read by the whole domain.
Here's what I use:

chdir("../"); // path to MyBB
define("IN_MYBB", 1);
require("global.php");
chdir("../");

echo $mybb->settings['bbname'] . ':' . $mybb->user['uid'];

It returns: Resource Forums:0 which means my uid would have to be 0 and it's not.
MyBB sets cookies to the root path (assuming installation at the root). According to PHP's setcookie documentation, it works on all paths.

Quote:The path on the server in which the cookie will be available on. 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.

I can't help you with debugging that, sorry.
You need to set the cookie path to "/" in the ACP. Once you log back in, the username will be accessible to the other folder.
The cookie path is set to that. Could it be something with Google SEO and the htaccess?

I have found the problem, just not a solution. I have my forum, then I have another domain 'rfbin.net' and that domain was set up by me on my VPS so that its virtual directory is resourceforums.net/rfbin which if you go there it would give you 'Resource Forums:1', but if you go to rfbin.net it wont because it's not the same cookie domain.

Any ideas?