Need Help urgently!!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
upabbi
Forum Newbie
Posts: 6
Joined: Thu Nov 11, 2004 9:19 pm

Need Help urgently!!!

Post 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
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post 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
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

Nice point, rehfeld. Now I understand the question #3 and your suggestion seems to me as a good solution for it.

-- Scorphus
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

i usually have them @localhost in my php.ini
and @webhost in .htaccess
upabbi
Forum Newbie
Posts: 6
Joined: Thu Nov 11, 2004 9:19 pm

Post by upabbi »

Thanks to all of u !!!!!!!!
Post Reply