vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Passing variables in the query string (https://vborg.vbsupport.ru/showthread.php?t=183942)

v0xb0x 06-30-2008 02:50 AM

Passing variables in the query string
 
Newb question.

I've been through the forums and haven't been able to find something in particular that answers my question. Thanks in advance for any comments.

Here's what I need to get done:

I have a non-vBulletin html page and I want to pass 3 variables from that page into a vBulletin page.

www.mydomain.com/forumdisplay.php?a=1&b=2&c=3

Integers like the above - no text.

When I get to the vBulletin page, how do I read the three variables to get the numbers 1,2,3?

Basic, I know. Please help.

Thanks!

Guest190829 06-30-2008 02:59 AM

PHP Code:


# Sanitize the variables, all of them are unsigned integers
$vbulletin->input->clean_array_gpc('r', array('a' => TYPE_UINT'b' => TYPE_UINT'c' => TYPE_UINT));

#After you call this function, the sanitized variables are stored in $vbulletin->GPC array

echo $vbulletin->GPC['a'] . $vbulletin->GPC['b'] . $vbulletin->GPC['c'];

# Prints '123'; 

Make sure you always sanitize your variables - I can't tell you how important that is!

v0xb0x 06-30-2008 03:06 AM

Danny, thanks for the quick response.

Where exactly do I place this PHP code?

In the template I want to read the query string in?

Again, many thanks for the help.

------------------------------------------

Edit!

Let me be more specific:

I want to pass values for forumid's into the vBulletin page from a non-vBulletin page.

I was planning on stuffing the query string with the following:

www.mydomain.com/forumdisplay.php?f=1&c=2

...where f=forumid and c=calendarid

That way I can populate variables inside the header template for custom navigation.

Again, I appreciate any help.

Dismounted 06-30-2008 05:58 AM

You can place the code in one of the "_start" hooks. For example, for showthread.php, showthread_start.

v0xb0x 06-30-2008 04:13 PM

Hanson, thanks for your reply. I'm sorry though, I'm not following.

I just went through the /forums directory and was unable to locate any file that ended with _start.*

Where does the showthread_start. file reside?

Is this the easiest way of passing variables from outside vBulletin into a vBulletin page?

Again, thanks so much for the help.

Opserty 06-30-2008 04:17 PM

There is no mention of "file" in Dismounted's post...

Create a Plugin with a Hook location as stated in Dismounted's post.

In answer to your second question, the answer is probably yes.

v0xb0x 06-30-2008 05:16 PM

Quote:

Originally Posted by Opserty (Post 1563173)
Create a Plugin with a Hook location as stated in Dismounted's post.

Ah, ok. Closer. Much Closer. Please get me over the last challenges...

Just completed the following:

1. Plug-in's are enabled.
2. Created a new plugin called navTransport
3. Hook Location is 'forumdisplay_start'
4. Inserted this code:
PHP Code:


# Sanitize the variables, all of them are unsigned integers
$vbulletin->input->clean_array_gpc('r', array('b' => TYPE_UINT'e' => TYPE_UINT'g' => TYPE_UINT)); 

Last question, how do I call the variables b, e and g from within the 'header' template now after I've passed them via the query string like this:

http://www.mydomain.com/forums/forum...=9&e=2&b=2&g=4

Again, thank you for the help.

Opserty 06-30-2008 05:38 PM

Typing:
PHP Code:

{$vbulletin->GPC['b']} 

Into your header template would probably do the trick.

v0xb0x 06-30-2008 06:14 PM

Not working. I've got to be missing something.

I have the following HTML tag in the header:

HTML Code:

<a href="/forums/forumdisplay.php?f={$vbulletin->GPC['b']}">
This should evaluate as:

Code:

<a href="/forums/forumdisplay.php?f=2">
However, it is evaluating as:

Code:

<a href="/forums/forumdisplay.php?f=">
The query string for the page is:

http://www.mydomain.com/forums/forum...=9&e=2&b=2&g=4

Perhaps there is something else that needs to be done?

Thanks again for all assistance...

Opserty 06-30-2008 06:46 PM

In your plugin temporarily add
PHP Code:

var_dump($vbulletin->GPC['b']); 

at the bottom of the PHP Code. Run the script again and check the output. There should be something like NULL or int(2) at the top of the screen. (You might need to view the HTML source of the page, but it should be listed at the very top).

You may find the rest of the page ceases to function correctly just ignore that, you can remove the line once you've followed the instructions.

Post what you get outputted here.

v0xb0x 06-30-2008 07:02 PM

Opserty...as you described, I got "int(2)" in the top LEFT of the page. (no need to view HTML)

So, the value is getting passed into the page successfully. This is good.

Why can I not call that variable in the HTML tag below? Do I need to escape the variable name perhaps?

HTML Code:

<a href="/forums/forumdisplay.php?f={$vbulletin->GPC['b']}">
Again, this should evaluate as:

HTML Code:

<a href="/forums/forumdisplay.php?f=2">
PERSONAL NOTE: Many thanks for your time and expertise. Please let me know how I can repay the favor.

Opserty 06-30-2008 07:47 PM

Ok that is good news. At least it is being passed correctly. (You can remove the var_... line if you haven't done so already).

In place of the var_... line add this:
PHP Code:

$specialvar_b =& $vbulletin->GPC['b']; 

Type $specialvar_b into your template, instead.

MoT3rror 06-30-2008 07:53 PM

The header template is eval in global.php so showthread_start is to late to insert variables into.

You can use to code after all your code in your plugin
PHP Code:

eval('$header = "' fetch_template('header') . '";'); 

or use global_start and use a if condition like this
PHP Code:

if(THIS_SCRIPT 'showthread')
{
//your code



Opserty 06-30-2008 07:58 PM

Oh, forgot about that :p Well spotted ;)

v0xb0x use the code you posted in post #7, but with the hook location global_start and combine it with the second piece of PHP code posted by MoT3rror. Then the code in post #8 should work, hopefully. :D

v0xb0x 06-30-2008 08:06 PM

Reading...

--------------- Added [DATE]1214861398[/DATE] at [TIME]1214861398[/TIME] ---------------

Quote:

Originally Posted by Opserty (Post 1563367)
...use the code you posted in post #7, but with the hook location global_start and combine it with the second piece of PHP code posted by MoT3rror. Then the code in post #8 should work, hopefully. :D

No joy. This does NOT pass the variable into the HTML tag.

Here's the current evolution:

1. Plug-in's are enabled in Admin-CP
2. Created a new plugin called navTransport
3. Hook Location is now 'global_start'
4. Inserted this code:

PHP Code:

if(THIS_SCRIPT 'showthread')
{
# Sanitize the variables, all of them are unsigned integers
$vbulletin->input->clean_array_gpc('r', array('b' => TYPE_UINT'e' => TYPE_UINT'g' => TYPE_UINT));


I have the following HTML tag in the header template

HTML Code:

<a href="/forums/forumdisplay.php?f={$vbulletin->GPC['b']}">
This should evaluate as:

HTML Code:

<a href="/forums/forumdisplay.php?f=2">
However, it is evaluating as:

HTML Code:

<a href="/forums/forumdisplay.php?f=">
The query string being passed into the page is:

http://www.mydomain.com/forums/forum...=9&e=2&b=2&g=4

So close here. Any other ideas? Is there some special 'escaping' I need to perform on the variable to expose it?

Again, thank you _both_ for your foo.

Opserty 06-30-2008 08:44 PM

Use:
PHP Code:

if(THIS_SCRIPT == 'forumdisplay')
{
# Sanitize the variables, all of them are unsigned integers
$vbulletin->input->clean_array_gpc('r', array('b' => TYPE_UINT'e' => TYPE_UINT'g' => TYPE_UINT));



v0xb0x 06-30-2008 08:44 PM

HOLD THE PRESSES!
HOLD THE PRESSES!

By withdrawing the code from the condition, the variable is being passed successfully!

So, here's what we have in the plugin - location is 'global_start':

PHP Code:

# Sanitize the variables, all of them are unsigned integers
$vbulletin->input->clean_array_gpc('r', array('c' => TYPE_UINT'e' => TYPE_UINT'g' => TYPE_UINT)); 

Here's what we have in the header template:

HTML Code:

<a href="/forums/forumdisplay.php?f={$vbulletin->GPC['e']}">
...which is being evaluated correctly as:

HTML Code:

<a href="/forums/forumdisplay.php?f=2">
Outstanding!

Gents, I appreciate your time, patience and expertise.

Please let me know how I can return the favor.

--------------- Added [DATE]1214867069[/DATE] at [TIME]1214867069[/TIME] ---------------

Follow Up!

Is there an easy way for me to get these values that I pass into the vBulletin templates to persist for the life of the user's session?

Is there a switch that we can call to maintain the values I pass in?

lendelgan@gmail 07-01-2008 03:28 AM

ok, I am having trouble with this same thing.

I have:

PHP Code:

$globals = array(
    
'a'    => TYPE_UINT,
    
'b'    => TYPE_UINT,
    
'c'     => TYPE_NOHTML,
);
$vbulletin->input->clean_array_gpc('r',$globals); 

(this gets accessed like: script.php?a=3&b=4&c=some+Value)
later I have
PHP Code:

$x $vbulletin->GPC['a']; 

however:
PHP Code:

echo $x

returns nothing but when we do
PHP Code:

print_r($vbulletin->GPC);
$x $vbulletin->GPC['a'];
echo 
$x

The value (3) gets returned.

this is irritating, because I can't figure out when the variable will be set and when it won't.

For
PHP Code:

$x $vbulletin->GPC['c'];
echo 
$x

Works fine. If someone could tell me what I am doing wrong I would appreciate it.

Dismounted 07-01-2008 06:58 AM

Make sure you globalise $vbulletin if calling from inside a function.

mooreaa 08-25-2008 05:29 AM

This is a helpful bit, but I'm having one little issue with it.

On topics with multiple pages when I click to go to the next page, my varible gets lost... is there anyway to scope variables to retain them within a thread?

IE when you visit ....showthread.php?t=3&myvar=2 then when I click on page 2 of this thread, i want it to go to showthread.php?t=3&page=2&myvar=2

Again, within the tread only... so I guess I need to somehow modify the thread pagination links

Marco van Herwaarden 08-25-2008 07:01 AM

You will need to pass variables between pages then. With any webbased script, each "page" is running in it's own environment so there are no variables inherit automatic from "previous pages".


All times are GMT. The time now is 07:02 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.01302 seconds
  • Memory Usage 1,825KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (8)bbcode_html_printable
  • (15)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (21)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete