forum.coppermine-gallery.net
Support => cpg1.4.x Support => Older/other versions => cpg1.4 themes/skins/templates => Topic started by: gregory on August 12, 2009, 11:11:33 pm
-
Hi,
I'm trying to use Coppermine Gallery on my website with my header.inc.php & footer.inc.php.
In "header.inc.php" file I include the file "function.inc.php". In "function.inc.php" I have a code below (just example):
$var99 = 50;
echo "1." . $var99;
function getVar()
{
global $var99;
echo "2." $var99;
}The result is:1. 50
2. What is the problem? All the variables are work but not inside the function when I define them through "global".
I'm testing this problem on the page: http://domain.com/gallery/thumbnails.php?album=1
Please help.
-
It's not in scope. Your code should be like this:
<?php
global $var99;
$var99 = 50;
echo "1." . $var99;
function getVar()
{
global $var99;
echo "2." . $var99;
}
getVar();
-
I know. It's just an example. Sure I call this function. That why I wrote "2. "
-
Did you try the code I posted?
-
Oh, I've missed the first "global".
Thank you very much! Everything is working.
Can you please describe me what was the problem? Is this header inside of another function or what?
-
I've found another problem.
"global $var;" is working but "global $var1, $var2" shows me only $var1.
-
I mean this global variables are working inside the function now but don't work outside this function as earlier)))
-
The code is included from within a function in Coppermine. Not sure what your issue with multiple globals is, works for me.
<?php
global $var1, $var2;
$var1 = 50;
$var2 = 60;
echo "1. " . $var1 . '.' . $var2;
function getVar()
{
global $var1, $var2;
echo "2. " . $var1 . '.' . $var2;
}
getVar();