I have just created an account with a new hosting company, and started some php from scratch. The following code outputs "Hello " because I have not put any global statements in there, but where to put them? index.php: <?php require 'authentication.inc'; echo"Hello $auth_name"; ?> Code (markup): authentication.inc: <?php require '1.inc'; require '2.inc'; getUserInfo("1"); //A simplified version of the real thing ... $auth_name=$userdata['username']; ?> Code (markup): 1.inc: <?php function do_sql($sql) { $conn = mysql_connect("localhost","mysqlusername","password"); mysql_select_db($db, $conn); $result=mysql_query($sql, $conn) or die(mysql_error()); } ?> Code (markup): 2.inc: <?php function getUserInfo($id) { $sql="SELECT * FROM users WHERE id='{$id}'"; $result=do_sql($sql); $userdata=mysql_fetch_array($result); return $userdata; } ?> Code (markup): This is a cut down (obviously) from the heaps of code already there, but the idea is that every page on the site will call 'authentication.inc' which goes off to check a few things, then sets up variables that are passed to the page that's calling it. 'authentication.inc' relies on 1.inc and 2.inc for functions. It's late, my brain has faded and given a clear head I could see through this, but please - how do I get "Hello Foo" to appear, given that the mySQL database has an entry "id=1, username=Foo"?
Don't use .inc as file extension, because all MySQL information such as username and password can be viewed by simply opening the page in the browser. Change the extensions to .php. This is not going to fix your problem, but you should keep this in mind.
Nico is still right, if you were to ever move servers and forget you would be out of luck. It's not hard to rename them and will save you grief in the future
This isn't really a global scope issue. In 2.inc you have the getUserInfo function that is returning an array of data, but you're not storing it when you call the function. in authentication.inc: getUserInfo("1"); //A simplified version of the real thing ... should be: $userdata = getUserInfo("1"); //A simplified version of the real thing ... I believe...