MyBB Community Forums
[How To?] Cookies in another directory - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Community Archive (https://community.mybb.com/forum-106.html)
+--- Forum: Archived Forums (https://community.mybb.com/forum-143.html)
+---- Forum: Archived Development and Support (https://community.mybb.com/forum-155.html)
+----- Forum: MyBB 1.6 (https://community.mybb.com/forum-138.html)
+------ Forum: 1.6 General Support (https://community.mybb.com/forum-127.html)
+------ Thread: [How To?] Cookies in another directory (/thread-151889.html)



Cookies in another directory - KoolAidModz - 2014-03-13

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?


RE: Cookies in another directory - Xen0n - 2014-03-13

If I'm not mistaken cookies can be read by the whole domain.


RE: Cookies in another directory - KoolAidModz - 2014-03-13

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.


RE: Cookies in another directory - Xen0n - 2014-03-13

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.


RE: Cookies in another directory - pavemen - 2014-03-13

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.


RE: Cookies in another directory - KoolAidModz - 2014-03-13

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?