PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Topic makes this sound noob, but I'm having a problem:
In my content management system JakeSys ([url=http://www.designsbyjake.net/jakesys/]demo[url]), I have certain functions such as check_level, smilestohtml, htmltosmiles, etc, and I want to use variables from config.php in those functions. Here is the structure of header.php that is in every page:
//start session etc
include("config.php");
//bunch-of-code
//I can use variables from config.php here!
function check_level($level){
//function code
//If I use a variable from config.php, it's just blank, like it's not set!
}
The problem I'm having is in the comments. Thanks if you can help .
<?php
//start session etc
include("config.php");
//bunch-of-code
//I can use variables from config.php here!
function check_level($level){
global $myVar,$myVar2;
//function code
//If I use a variable from config.php, it's just blank, like it's not set!
}
?>
or if your variable in config.php never change set them as constants.
function check_level($req_lvl){
global $redir_to_login; //This variable is set in config.php
if($_SESSION['level']>=$req_lvl){
return true;
}else{
if($redir_to_login){
echo "<script language="JavaScript">";
echo "location.href="index.php?page=login";";
echo "</script>";
return false;
}else{
echo "You lack permission to use access this page.<br />";
echo "Your current level is <strong>".$_SESSION['level']."</strong> (".$_SESSION['level_name'].").<br \>";
echo "The required level level is <strong>".$req_lvl."</strong> (".level_name($req_lvl).").<br \>";
return false;
}
}
}
xjake88x wrote::-D Ok so I can i use a $ though.. because theres probably hundreds of instances of the config variables as variables in my other files..
For global variables you use a $ for [php_man]constants[/php_man] you dont.
if they are set outside a function, or set through global inside a function, you just need to global them inside your next function.. or pass them in (which is generally better).. depending on the data/usage