Hi There !!,
I am novice PHP/MySql programmer . Currently i am working on a server side project . I am facing some problems. please help me to resolve those problems.
1. How can I define global variables in PHP , for exmaple i need one variable throught my project how can i sote it as global.
2. I am including one .inc file through require but i need to include the path where this file is lying. where can i specify the include path.
3. If i upload my project on my own website how can i change the include path for .inc file.
Please reply back soon
Thanks
Upasna
Need Help urgently!!!
Moderator: General Moderators
- scorphus
- Forum Regular
- Posts: 589
- Joined: Fri May 09, 2003 11:53 pm
- Location: Belo Horizonte, Brazil
- Contact:
Hi, welcome to DevNetwork!
1. Variable scope
3. Please remodel/rewrite your question.
-- Scorphus
1. Variable scope
Code: Select all
require('/path_to/file.php');
require('../path_to/file.php');-- Scorphus
if your local dev box is set up a bit differently i have always used a config file to solve it
also, constants are available in any scope inside php, including functions and classes
Code: Select all
if ($_SERVER['SERVER_NAME'] === 'localhost') {
// settings for localhost
define('INCLUDE_DIR', 'path/to/inc/'); // define a constant
} else {
// settings for real server
define('INCLUDE_DIR', 'other/path/to/inc/'); // define a constant
}also, constants are available in any scope inside php, including functions and classes