I am trying to figure out how to change the globals in my script. I am trying to make it active without turning on globals. Here is a sample of one page. How would I rewrite this to omit global?
<?php function adminAuth() { global $ad_url; if (!isset($_SESSION['aduser_name']) || !isset($_SESSION['aduser_passwd'])) { $_SESSION = array(); session_destroy(); mysql_close; header("location: $ad_url/"); exit; } else { $res = mysql_query("select value from adminvals where field='adloginid'"); $sdblogin = md5(mysql_result($res, 0)); $res = mysql_query("select value from adminvals where field='adpasswd'"); $sdbpasswd = md5(mysql_result($res, 0)); if ($_SESSION['aduser_name'] == $sdblogin && $_SESSION['aduser_passwd'] == $sdbpasswd) { return; } else { $_SESSION = array(); session_destroy(); mysql_close; header("location: $ad_url/"); exit; } } }The current way to solve this, go OOP and get away from procedural programming. Then you either define a constant or pass the variable to a function.
You should also stop using mysql functions.
Don’t use md5. It is not secure. Use bcrypt.
To answer your question as previously mentioned, you need to pass the variable to the function.
myFunction($myvar);
function myFunction($myvar){
//Function stuff
}