Reputation: 686
I'm new to PHP, and i start to use XAMPP to build the site. I have code below
db.php:
<?php
$hostName='localhost';
$userName='xxxxxxxxx';
$userPass='xxxxxxxxx';
?>
and a test.php:
<?php
include 'db.php';
echo $hostName;
?>
but now it show me Notice: Undefined variable: hostName
what i found is the register_globals need to set "on" in php.ini, but after i set, the XAMPP show: Directive 'register_globals' is no longer available in PHP when i restart XAMPP.
i move the same code to Hosting24 but it's work, anyone can help?
Upvotes: 8
Views: 9901
Reputation:
I had a similar issue, what happened to be the issue was the file access permissions for the files
Upvotes: 0
Reputation: 1409
I just got bit by a similar problem - definitely not OP's problem but falls under the question's title.
In my case I had PHP short tags disabled on the server, but the included file accidentally used short tags. When the file was included, functions were undefined and there were no inclusion errors. What I think happens in this situation is that the file is included but treated as an empty file.
If you have an "undefined" problem after inclusion/requirement, check your file tags - just in case.
Upvotes: 6
Reputation: 2361
The only reason that this can happen is if the file db.php
is not included properly. Check your log files for why this happens.
When you include a file PHP treats this file as if you copy/pasted the code directly into the including file. So all your variables defined in the included file will have the same scope as the including file and hence are available.
In your example, it should just work. So my answer would be: check your log files for include errors. Make sure logging is set to FULL.
Upvotes: 0