Page 1 of 1

Need Help urgently!!!

Posted: Thu Nov 11, 2004 9:33 pm
by upabbi
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

Posted: Thu Nov 11, 2004 10:06 pm
by scorphus
Hi, welcome to DevNetwork!

1. Variable scope

Code: Select all

require('/path_to/file.php');
require('../path_to/file.php');
3. Please remodel/rewrite your question.

-- Scorphus

Posted: Fri Nov 12, 2004 12:43 am
by rehfeld
if your local dev box is set up a bit differently i have always used a config file to solve it

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

Posted: Fri Nov 12, 2004 6:45 am
by scorphus
Nice point, rehfeld. Now I understand the question #3 and your suggestion seems to me as a good solution for it.

-- Scorphus

Posted: Fri Nov 12, 2004 9:23 am
by phpScott
in your php.ini file if you have access to it you can set the include_path to look in several different directories of where you store your files. Otherwise you can just keep the levels the same and have your include files up one directrory from your web pages are served from.

Posted: Fri Nov 12, 2004 10:04 am
by timvw
i usually have them @localhost in my php.ini
and @webhost in .htaccess

Posted: Sun Nov 14, 2004 9:59 pm
by upabbi
Thanks to all of u !!!!!!!!