View Full Version : Custom Global Variables
Boeman
06-04-2003, 03:21 AM
One of my external scripts referenced in PHPInclude requires the use of a global variable called $count_border to which it adds a count each time the script is called (it could be several times on a single page). I've tried inserting it into phpinclude, putting "global" before the variable and even adding it to the index.php file but to no affect. Is there a straightforward to do this with VB?
Thanks.
Xenon
06-04-2003, 04:13 PM
the command global has to be used in the function which calls the script :)
Boeman
06-04-2003, 04:32 PM
Today at 06:13 PM Xenon said this in Post #2 (https://vborg.vbsupport.ru/showthread.php?postid=404362#post404362)
the command global has to be used in the function which calls the script :)
Does the PHP code contained in the external script have to be written as a fuction? At the moment it is a basic if statement.
Xenon
06-04-2003, 04:50 PM
no need for it to be a function, but if you call it from within a function you need to make vars global,n if you don't call it from within a function you also don't need to make the var global
Boeman
06-04-2003, 06:06 PM
Today at 06:50 PM Xenon said this in Post #4 (https://vborg.vbsupport.ru/showthread.php?postid=404389#post404389)
no need for it to be a function, but if you call it from within a function you need to make vars global,n if you don't call it from within a function you also don't need to make the var global
Well, it's actually an external script referenced in phpinclude and is called using the variable defined in phpinclude. I put the variable (in this case $forum_border) in formbit 1. All it needs to do is keep track of how many times it is called and based on that decides what action to take and then adds one to $border_count. So basically it is a variable within the external script that needs to be global. Maybe you have an example that spells it out for a php-impared man such as myself? :)
Boeman
06-05-2003, 04:56 AM
can anyone else help?
Xenon
06-05-2003, 04:58 AM
forumbit 1 is created in the makeforumbit FUNCTION of index.php so you have to globalize the var in that function.
but you won't see an effect, ast the forumbit is executed AFTER phpinclude, so your script won't show up the right value
Boeman
06-05-2003, 05:04 AM
Today at 06:58 AM Xenon said this in Post #7 (https://vborg.vbsupport.ru/showthread.php?postid=404650#post404650)
forumbit 1 is created in the makeforumbit FUNCTION of index.php so you have to globalize the var in that function.
but you won't see an effect, ast the forumbit is executed AFTER phpinclude, so your script won't show up the right value
Ah I see. So in other words there's no way I can keep an accurate counter variable with custom php code under the formbit templates?
Xenon
06-05-2003, 05:19 AM
there is a way, but it's not as easy as you tried to do it...
Boeman
06-05-2003, 05:30 AM
Today at 07:19 AM Xenon said this in Post #9 (https://vborg.vbsupport.ru/showthread.php?postid=404664#post404664)
there is a way, but it's not as easy as you tried to do it...
The script uses the counter only as a means of testing whether or not it was called for the first time with forumbit 1. If this is the first call go to option 1, if it has been called before go to option 2. Laid out like this:
If ($count_border < 1) {
Do this
} else {
Do this instead
}
I tried putting in $count_border variable as a global right after the line "return $forumbits;" as $count_border++; so it wouldn't equal 1 when forumbit is used next time. Of course it didn't work but implanting some kind of variable and altering its value right after the function is called so the external script would know the value has changed might just be all I need.
Would love to hear your ideas :)
Boeman
06-06-2003, 04:00 PM
anyone?
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.