Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-10-2012, 07:37 AM
ohadpartuck ohadpartuck is offline
 
Join Date: Mar 2012
Posts: 138
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default pass username and id to a php page in vbulletin

hi,
I tried to pass the variable value by doing this
in the global start hook:

PHP Code:
$arr $vbulletin->userinfo;

$aaa $arr["username"]; 
and in the php page which is in a iframe in a vbulletin template here

PHP Code:
<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

PHP Code:
echo "aaa is " $aaa
Reply With Quote
  #2  
Old 06-10-2012, 08:46 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:

Code:
<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}&amp;userid={vb:raw bbuserinfo.userid}"></iframe>
Reply With Quote
  #3  
Old 06-10-2012, 08:50 AM
ohadpartuck ohadpartuck is offline
 
Join Date: Mar 2012
Posts: 138
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #4  
Old 06-10-2012, 08:55 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 06-10-2012, 10:40 AM
ohadpartuck ohadpartuck is offline
 
Join Date: Mar 2012
Posts: 138
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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/..._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??
Reply With Quote
  #6  
Old 06-10-2012, 10:57 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ohadpartuck View Post
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.
Reply With Quote
  #7  
Old 06-10-2012, 11:31 AM
ohadpartuck ohadpartuck is offline
 
Join Date: Mar 2012
Posts: 138
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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)

PHP Code:
 include('global.php');
    
$arr $vbulletin->userinfo;
    echo 
$arr['userid']; 
but it didn't work .
Reply With Quote
  #8  
Old 06-10-2012, 01:19 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #9  
Old 06-12-2012, 04:30 AM
ohadpartuck ohadpartuck is offline
 
Join Date: Mar 2012
Posts: 138
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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

PHP Code:
include("../Forum/global.php"); 
but then I get an error including class bootstrap..
I don't understand the reasoning..
Reply With Quote
  #10  
Old 06-12-2012, 11:15 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ohadpartuck View Post
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:

Code:
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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:03 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07325 seconds
  • Memory Usage 2,260KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (5)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete