View Full Version : pass username and id to a php page in vbulletin
ohadpartuck
06-10-2012, 07:37 AM
hi,
I tried to pass the variable value by doing this
in the global start hook:
$arr = $vbulletin->userinfo;
$aaa = $arr["username"];
and in the php page which is in a iframe in a vbulletin template here
<iframe id="livechat" frameborder="0" width="100%" height="900" allowtransparency="true" marginwidth="0" marginheight="0" src="http://www.mydomain.com/mypage.php"></iframe>
and the page it self is
echo "aaa is " . $aaa;
The two php scripts are completely separate, so you can't just set $aaa in one and use it in another. Probably you want to do something like pass it as a parameter, like:
<iframe id="livechat" frameborder="0" width="100%" height="900" allowtransparency="true" marginwidth="0" marginheight="0" src="http://www.mydomain.com/mypage.php?username={vb:var bbuserinfo.username}&userid={vb:raw bbuserinfo.userid}"></iframe>
ohadpartuck
06-10-2012, 08:50 AM
hi kh99,
thanks for the quick response.
I know the way you displayed, but that paramer musn't be displayed and or controled by the user because it enable/disabled access to restricted areas.
So I must pass the variable directly to the php file as a variable and not via the URL.
In that case I don't know how you'd do it other than having your script check if the user is logged in, the same way that a vbulletin script would do it. You might want to look at this article: https://vborg.vbsupport.ru/showthread.php?t=228112 . If you follow those instructions to include global.php in your script then you can just user $vbulletin->userinfo.
Another possibility might be to "include" your script, save or capture the output, then include that in a template instead of using an iframe.
ohadpartuck
06-10-2012, 10:40 AM
thanks again kh99.
I tried them both but
1. the first one - the php file in the iframe doesn't recognize the https://www.vbulletin.com/docs/html/templates_externalfiles
global variable $vbulltein
global $vbulletin;
global $arr;
$arr = $vbulletin->userinfo;
tried every thing.
2. and the second solution - it is recognized but it displays the php on the whole page and not just in the middle.
:(
3. I tried defining a global variable $_SESSION['userid'] = ...
in the global_start hook but still nothing.
why is this so hard to do??
why is this so hard to do??
I think maybe you're trying to make mypage.php do something it wasn't designed to do. Is this something you wrote, or are you trying to take a script you got from somewhere else and include it on your page? If it's something you wrote (or if you at least understand how it works) then you should be able to change it to either include the vb global.php or else work as a php file included in a plugin. I can't tell you exactly how to do either of those without seeing it.
ohadpartuck
06-10-2012, 11:31 AM
hi kh99,
I did tried including the global.php file in myfile.php (the file is in the same directory as the global.php file)
include('global.php');
$arr = $vbulletin->userinfo;
echo $arr['userid'];
but it didn't work .
It seems like that should have worked. Is your script in the same folder as global.php? Are you calling that code in a function, or outside any function?
ohadpartuck
06-12-2012, 04:30 AM
it worked only when I moved the script to the same folder as global.php.
but my script shouldn't be there.
My script(s) are in an above folder. meaning in order to include the global.php I need to
include("../Forum/global.php");
but then I get an error including class bootstrap..
I don't understand the reasoning..
it worked only when I moved the script to the same folder as global.php.
Then what you need to do is chdir() to the forum directory before including global.php, like:
chdir('./forum');
include('global.php');
then you can chdir() back to your script directory if you need to.
You need to do this because the vb code has relative paths for including other files.
ohadpartuck
06-13-2012, 06:54 AM
Actually, it's not working again...
here is the code
(it's working on the local host but not on the server)
chdir('../Forum');
require_once('global.php');
$arr = $vbulletin->userinfo;
$usergroup = $arr['displaygroupid'];
if ($usergroup=="")
$usergroup = $arr['usergroupid'];
//change dir back
chdir('../backtomydir');
--------------- Added 1339582466 at 1339582466 ---------------
sorry.. it's not working I didn't check it right.. it's not working on the server
Hmm...what happens exactly? Are you getting global.php included successfully but you're not logged in? In the adminCP, in Options > Cookies and HTTP Header Options > Path to Save Cookies, you need to have the path set to '/' (but I believe that's the default). And you custom script is available through the same domain name, right?
ohadpartuck
06-13-2012, 11:36 AM
the custom script is under the same domain name meaning
my script is on
www.myDomain.com/mydir
and the forum is on
www.myDomain.com/Forum
but the path to save cookies in set to /Forum/
as I see it.
Is that wrong?
i don't want to change it because there is a warning there that states
"Entering an invalid setting can leave you unable to login to your forum."
but the path to save cookies in set to /Forum/
as I see it.
Is that wrong?
i don't want to change it because there is a warning there that states
"Entering an invalid setting can leave you unable to login to your forum."
It's not "wrong", but I think it might be the problem. The cookie needs to be sent to for you to be "logged in", and since your script is not in /Forum/, the cookie's not getting sent and you're always going to appear logged out.
Changing it to / should be fine, in fact it should be one of the choices from the dropdown menu. If you have a live forum it might be that users will have to log in again even if they've chosen "Remember Me". If you do end up unable to log in (which I don't think is going to happen), you can upload tools.php (which should be in the "do not upload" folder of the distribution) and use that to reset the path.
ohadpartuck
06-13-2012, 12:03 PM
Where is the path of "tools.php"?
I searched the whole Forum directory and the closest I've found is "usertools.php"
in the admicp folder.
and I don't see how my path to /Forum/ is saved there.
isn't that saved somewhere in the DB?
Sorry I wasn't clear. Forget about tools.php - it's a file that came with your vb package that you *would not* have uploaded, so you won't find it on your server.
ohadpartuck
06-13-2012, 01:03 PM
so, I have no option of backing up if I indedd can't log in after this operation?
No, then you would need to find tools.php, it's just that I'm fairly certain that you won't have that problem.
If you download the distribution zip file for your version of vb (if you don't already have it). When you unzip it, there should be a "do_not_upload" folder, and in that folder there's a file named "tools.php". If you need to you can upload that to the admincp folder on you server, then in your browser go to "www.mysite.com/forum/admincp/tools.php" (using your own domain name and forum path, of course). You then need your customer number, the one you use to log in to the vbulletin.com customer area. After entering that, there's a "Reset Cookie Path" link you can use to reset it.
To make things more complicated, if you're running version vb4.2.0, tools.php doesn't work. Here's thread about that: https://www.vbulletin.com/forum/showthread.php/402513-class_bootstrap_framework-php-on-line-65 . If this applies to you and you want to make the change in the last post, that does appear to fix the issue.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.