PDA

View Full Version : identify user in a different folder then the forum


ohadpartuck
09-03-2012, 03:01 PM
Hi,
I have a another site which is not a part of the vbulletin forum but it's located in the parent directory.
vbulletin forum => s-maof/Forum dir
another site => s-maof/aaa dir

I want to idintify users that are logged in the forum in the other site.
I have included this code:
$dir = dirname(dirname(__DIR__)).'/Forum';
chdir($dir);
include dirname(dirname(__DIR__)).'/Forum/global.php';
print_r($arr = $vbulletin->userinfo);
$userid = isset($arr['userid']) && $arr['userid'] != 0 ? $arr['userid'] : -1;
echo "userid = " . $arr['userid'];
echo "username = " . $arr['username'];

I get the $vbulletin->userinfo array, but I am seen as not logged in,
even though I am.

Any help?

kh99
09-03-2012, 03:08 PM
Since it works using cookies, that will only work if you set "Path to Save Cookies" to "/" (should be one of the choices in the dropdown menu). That's in "Cookies and HTTP Header Options" section of the options. You might have to log out and back in again for it to take effect.

Lynne
09-03-2012, 03:08 PM
You need to actually activate a session. Are you seen in the session table at all?

ohadpartuck
09-06-2012, 09:39 AM
Since it works using cookies, that will only work if you set "Path to Save Cookies" to "/" (should be one of the choices in the dropdown menu). That's in "Cookies and HTTP Header Options" section of the options. You might have to log out and back in again for it to take effect.

whouldn't that ruin my normal/Forum users.
The domain that I am talking about is in :
mydmoain.com/myFolder/app

wheras my regular vbulletin forum users are in
mydomain.com/Forum

I want to detect my users in both urls!

kh99
09-06-2012, 09:57 AM
whouldn't that ruin my normal/Forum users.

It shouldn't. It should just make it so that the vbulletin cookies are sent on any request to your server, instead of being sent only if the request starts with /Forum. I think your problem is that if your custom script is in /myFolder/app, the cookies aren't being sent because it doesn't start with /Forum.

It could cause a problem if you have more than one forum installed on your server, but if you do, I think you could fix that by using a unique cookie prefix for each one.

ohadpartuck
09-06-2012, 10:17 AM
It shouldn't. It should just make it so that the vbulletin cookies are sent on any request to your server, instead of being sent only if the request starts with /Forum.

My site is live and contain many users, The configuration suggested has a warning stating
Entering an invalid setting can leave you unable to login to your forum


so i'm a little hesitent about changing it (leaving my users unable to login and me unable to change it).
isn't there another way. something like:

$dir = dirname(dirname(dirname(dirname(__DIR__)))) . '/Forum/';
chdir($dir);
include $dir .'global.php';
$arr = $vbulletin->userinfo;
$userid = isset($arr['userid']) && $arr['userid'] != 0 ? $arr['userid'] : -1;
echo "userid = " . $arr['userid'];
echo "username = " . $arr['username'];

The $dir variable is correct and I am able to inlcude the global.php file.
(I get an empty username and id..)

kh99
09-06-2012, 11:04 AM
I understand your concern, but I'm not sure what else to tell you. I think you either need to change the cookie path, or else your custom script needs to be under the /Forum directory. The issue has to do with when the user's browser decides to send the cookies, so you can't fix that by doing a chdir() in your script (because by the time your script is running, the cookies have either been sent with the request, or they weren't).

There is a file that comes with the vb distribution, in the "do not upload" folder, called tools.php. It allows you to fix certain things without neding to log in, by uploading that file to your admincp directory and then pointing your browser to admincp/tools.php (don't do it until you need it, because some other things won't work when the tools.php file is present). Anyway, one of the things it lets you do is reset the cookie path, so if you run in to a problem you should be able to fix it that way.

ohadpartuck
09-06-2012, 01:27 PM
hi kh99,
I have changed the setting to 'Path to Save Cookies' to '\'
logged out and back in again.
with the browser tried this sctipt again:
$dir = dirname(dirname(dirname(dirname(__DIR__)))) . '/Forum/';
chdir($dir);
echo "including" . include 'global.php';
print_r($arr = $vbulletin->userinfo);
$userid = isset($arr['userid']) && $arr['userid'] != 0 ? $arr['userid'] : -1;
echo "userid = " . $arr['userid'];
echo "username = " . $arr['username'];

and got an empty username and id again.

kh99
09-06-2012, 01:45 PM
Hmm...well, at least it didn't break the forum. :) So are you seeing *any* info in $vbulletin->userinfo? (edit: I see now in your first post you say you are). You could try using something like Firefox with Firebug (the net tab) and see if the cookies are being sent (I still think it might be a cookie problem).

Also, maybe try include "./global.php" (with the ./ in front). Looking at your code I think you know php much better than I do, and I don't know why it should make any difference, but I seem to remember someone else having an issue before that was fixed by adding the ./ (Edit: but now that I see where you said you *are* getting some info in $vbulletin, it must be included correctly so probably that's not it).

Edit: is the code you posted inside a function? That's another thing that doesn't work.

ohadpartuck
09-06-2012, 02:41 PM
no, it's empty,
I taught it was the xcache.var_size,
so I changed it from 0M to 2M (restart apache) and tried again (no luck)..

change it to ./global.php - also nothing.

the $vbulletin->userinfo is empty.

It was in a function -->I took it out from it and now the $vbulletin->userinfo is not empty but i get
userid = 0
and
username = not registered

kh99
09-06-2012, 02:48 PM
OK, well, it's getting closer. I think it's possible to do the include in a function, but you have to define some variables as global first. I know $vbulletin is one of them, but I can't remember what the others were. I know user Disasterpiece was trying to do that a while back and I think he finally succeeded.

Edit: here's the thread I was thinking of: www.vbulletin.org/forum/showthread.php?t=274455 . It looks like you also need $bootstrap as global. And it does look like maybe he wasn't completely successful (at least the last time he posted in that thread).

ohadpartuck
09-06-2012, 03:05 PM
I have change the global.php file like so :

global $bootstrap;

$bootstrap = new vB_Bootstrap_Forum();

but still the same ($vbulletin->userinfo shows not regitered)

kh99
09-06-2012, 03:14 PM
OK, sorry for the confusion - those comments were only about being able to include global.php from a function. And BTW, you could put the global statement in your code before it's included, that way you don't need to modify the vbulletin code.

But, if you put your include outside any function you should see the user info, so obviously you still have some other problem. One thing you might do is turn on errors in your custom script, if you haven't already. I think you can put error_reporting(E_ALL) and ini_set('display_errors', 1) at the beginning of your file.

Sorry I'm not a lot of help, but this is a question that's asked periodically, and it's usually the cookie thing.

ohadpartuck
09-06-2012, 03:37 PM
1. tried global $bootstrap in the main php file.
2. tried error_reporting(E_ALL) and ini_set('display_errors', 1) - got errors but nothing to do with global.php
3. what do you mean by "and it's usually the cookie thing."? I have checked my browser cookies and I see the relevant cookies - bb_userid , etc...

kh99
09-06-2012, 03:41 PM
3. what do you mean by "and it's usually the cookie thing."? I have checked my browser cookies and I see the relevant cookies - bb_userid , etc...

I just mean that as far as I know, whenever someone asked, changing the cookie path has fixed the problem.

You said you see the cookies - do you have a way to look at the request that's sent to your custom script to see if it includes the cookies? (Edit: or I suppose another way would be to have your custom script check to see if they're set).

ohadpartuck
09-06-2012, 03:56 PM
I see that the cookie bb_userid is set in my forum domain but if try to check in the other domain
isset($_COOKIE['bb_userid'])

then I don't see the cookie. niether do I see it in the page cookies..

it's weird . aren't cookies suppose to be general for the whole browser?

kh99
09-06-2012, 04:11 PM
To be honest I don't know a lot about it. But my understanding is that cookies are only sent back to the domain/path that set them (so that you're not letting every site see all your cookies). I believe the script that sets the cookie can modify the cookie to allow it to be sent to other scripts. Here's a paragraph from the Wikipedia article on http cookies:

Domain and Path

The cookie domain and path define the scope of the cookie—they tell the browser that cookies should only be sent back to the server for the given domain and path. If not specified, they default to the domain and path of the object that was requested. An example of Set-Cookie directives from a website after a user logged in:


Set-Cookie: LSID=DQAAAK…Eaem_vYg; Domain=docs.foo.com; Path=/accounts; Expires=Wed, 13-Jan-2021 22:23:01 GMT; Secure; HttpOnly
Set-Cookie: HSID=AYQEVn….DKrdst; Domain=.foo.com; Path=/; Expires=Wed, 13-Jan-2021 22:23:01 GMT; HttpOnly
Set-Cookie: SSID=Ap4P….GTEq; Domain=.foo.com; Path=/; Expires=Wed, 13-Jan-2021 22:23:01 GMT; Secure; HttpOnly
......

The first cookie LSID has default domain docs.foo.com and Path /accounts, which tells the browser to use the cookie only when requesting pages contained in docs.foo.com/accounts. The other 2 cookies HSID and SSID would be sent back by the browser while requesting any subdomain in .foo.com on any path, for example www.foo.com/.

Cookies can only be set on the top domain and its sub domains. Setting cookies on www.foo.com from www.bar.com will not work for security reasons.


that brings up another question - are your two sites on the same (top-level) domain? I believe leaving the "cookie domain" setting blank (which seems to be the default) will allow it to be sent to all related subdomains, but if you have an entirely different domain name for your other site, that might be the issue.

ohadpartuck
09-06-2012, 06:35 PM
that brings up another question - are your two sites on the same (top-level) domain? I believe leaving the "cookie domain" setting blank (which seems to be the default) will allow it to be sent to all related subdomains, but if you have an entirely different domain name for your other site, that might be the issue.

as I stated - they are both under s-maof.com
on is
s-maof.com/GoldSig/app
and the other
s-maof.com/Forum

I have set the cookie path to '/' (as you advised) which means the cookies are being sent to s-maof.com.
from your logic - I should be able to see them from s-maof.com/GoldSig/app due to the face that it is a subdomain of s-maof.com.

kh99
09-06-2012, 07:21 PM
I did see in your first post where it looked like they were at the same domain, but thought I'd make sure. You're right, as far as I know the cookies should be sent with the settings you have.

Sorry, maybe someone else will have an idea.

ohadpartuck
09-09-2012, 09:01 AM
Hi kh99,
thank for all your help,
I got it working with

chdir(FORUM_DIR);
include './global.php';
$arr = $vbulletin->userinfo;

* It can't be used inside a function for some reason..

It's weird sometimes it worked and sometimes it didn't.
now it workes all the time.

Thanks again
:D

--------------- Added 1347188933 at 1347188933 ---------------

damm,
it stopped working again for some reason... It works only on chrome

kh99,
what can be the cause?

it worked fine, recognized me and another user, and now it stopped again..

ohadpartuck
09-20-2012, 11:49 AM
I did see in your first post where it looked like they were at the same domain, but thought I'd make sure. You're right, as far as I know the cookies should be sent with the settings you have.

Sorry, maybe someone else will have an idea.


Hi kh99,
It's still the same problem.
It works on the localhost - perfectly but not on the remote host.

Maybe I can extract those details from the browser cookies
I can sees that I have
bb_sessionhash and PHPSESSID

Is there a way to match those to the userid ? (I can manage from there.. :) )


Any idea at all?