...

View Full Version : Config File Include anf Functions



Big-Pat
11-15-2007, 08:03 PM
I have a file 'config.php' that has things like DB user/passwords. That is included into 'functions.php', which stores all my functions. That file is included into all of my pages. It doesn't work. I can get it to work if I just put the contents of config.php into functions.php, but not when I just use the include.

Is there a reason this doesn't work?(I'm not getting any errors.) Is there a better way to do it?

CFMaBiSmAd
11-15-2007, 08:14 PM
The path to the file is probably not correct if you are using relative paths. Check your web server log for errors and/or turn on full php error reporting. Posting your folder structure and your code will also help in getting an answer.

aedrin
11-15-2007, 08:54 PM
Is there a reason this doesn't work?(I'm not getting any errors.)

So how do you know it's not working?

CFMaBiSmAd
11-15-2007, 09:06 PM
Good question. :thumbsup:

I guess I assumed that someone would exhaust every possible means and troubleshooting technique available to them to find out what is happening in their code before running to a forum to ask what their code was doing without posting their actual code for someone to see. :eek: <--- Could not find a sarcastic smiley, so he will have to do.

aedrin
11-15-2007, 10:07 PM
I was going to respond with witty bolding, but the forum has a silly filter. So I am refraining from the aforementioned action.

Either way. Yeah, you'd think that this forum is more of a last resort as it is the slowest method of finding a solution. But sometimes it seems to be...



Error reported
Post topic on forum
Wait
Copy and paste solution


Or something along those lines. Oh well.

Big-Pat
11-15-2007, 10:41 PM
I know it's being included because, if I change the file name I do get errors. And I know it's not working because when I move the variable assignments into the functions.php file every thing works fine, but when only using config.php I get nothing back from mySQL and I can't print any of the variables.

Also on a related side note, is there a way to tell the php engine to pretend a specific dir is the root dir?

Big-Pat
11-15-2007, 10:47 PM
There isn't some odd scope thing that I'm forgetting is there. I've declared them as global inside the function. Is that all I need to do? And just to make sure, there isn't anything preventing me from including in an included file? Sorry, I haven't done much with PHP functions, or any PHP in almost a year.

aedrin
11-15-2007, 10:47 PM
but when only using config.php I get nothing back from mySQL and I can't print any of the variables.

What?

You can't print any of the variables? Why not?

Big-Pat
11-15-2007, 10:51 PM
Well I assume, it's because there's nothing in them. And just to clarify, I mean any that are assigned in config.php

CFMaBiSmAd
11-15-2007, 10:58 PM
In case it has not already been said enough times, posting your code that is causing the symptoms is the only way to get a definitive answer. Otherwise the twenty-question guessing game could go on for a couple of more hours before the cause is found.

Round 5 - ding - My guess is that your config php file does not contain any php tags and is not being parsed as php code.

aedrin
11-15-2007, 11:42 PM
Well I assume, it's because there's nothing in them.

Two wrongs don't make a right!

Never assume when debugging, and not being able to output variables has nothing to do with them containing nothing.

Look into var_dump().

barkermn01
11-16-2007, 12:20 AM
ok mate some little problems with that setup
one all your functions in one file is verry verry bad secqurity risk if you get hacked
and Every page that uses a function Has to load all the functions you have rote into the PHP Buffer Very slow this would work if you have a mast file site and you set it to requre E.G index.php?p=(Your Page) and the index use once on the Functions that way all the functios are loaded into the PHP and it is not reloading them every page that uses them

but you are better of Setting up the function in Differnt files like
SQL_Fucts.php
Read_fucts.php
ect...
And only include the onces you ned but if you are using all differnt ones from eatch alot of the time use the first one it mutch easyer on PHP and your Site will load quicker
second if you are ding this


Page one index.php

include("file/this.php")



this.php

include("second.php")

And the second file is in the files/second.php it will not work as the fil has to be realative to the host file index.php

Inigoesdr
11-16-2007, 01:42 AM
ok mate some little problems with that setup
one all your functions in one file is verry verry bad secqurity risk if you get hacked
... what? How is it any less secure than having the functions in different files?

and Every page that uses a function Has to load all the functions you have rote into the PHP Buffer Very slow this would work
You're assuming that they have a huge list of functions, and that every function(or almost every function) isn't needed on every page.


second if you are ding this


Page one index.php

include("file/this.php")



this.php

include("second.php")

And the second file is in the files/second.php it will not work as the fil has to be realative to the host file index.php
That is incorrect.

Big-Pat
11-16-2007, 03:30 AM
That is incorrect.
Uh.. No.. it's not. Thanks barkermn that fixed it.

But, is there a way to tell the php engine to use a specific directory as root to just avoid this in the future all together? Or is there some sort of way to make an "intrinsic" variable that will be available to anywhere without defining it?


ok mate some little problems with that setup
one all your functions in one file is verry verry bad secqurity risk if you get hacked
I don't understand why. If they can get to one of the files wouldn't they be able to get to all of them? And I have/will be take(ing/en) some safety steps as well. That's actually the reason I'm using functions in the first place. I plan to have the included files above the site's root (from apache's pov) dir and the ftp is only accessible from inside my house(thats where the server is). The only thing that is accessible from outside are port 80,110,and 25 (at least that's the plan). And soon to be the secure equivalents as soon as I get my new server configured. (It's hard to jump into the deep end of the Linux+command line configuring end of the pool, when my only Linux experience is in a GUI, and my web server admining experience is limited to installing xampp on an old xp system.)


Every page that uses a function Has to load all the functions you have rote into the PHP Buffer Very slow this would work if you have a mast file site and you set it to requre E.G index.php?p=(Your Page) and the index use once on the Functions that way all the functios are loaded into the PHP and it is not reloading them every page that uses them


Why would that be better? Wouldn't the functions still be loaded and unloaded every time the page is requested? I had planed on doing that, because I wanted to mess around with mod rewrite (I think that's what it's called), but I might make it more of a priority now if it really makes a difference.

Inigoesdr
11-16-2007, 05:12 AM
Uh.. No.. it's not.
Yes, it is.. the only time it wouldn't be true would be if you were trying to include a file in the sub-directory with the same name as a file in the working directory.

Files for including are first looked for in each include_path entry relative to the current working directory, and then in the directory of current script.
test.php

<?php
echo 'in test<br />';
echo __FILE__ . '<br />';
include('test/page.php');
?>
test/page.php

<?php
echo 'in page<br />';
echo __FILE__ . '<br />';
include('page2.php');
?>
test/page2.php

<?php
echo 'in page2<br />';
echo __FILE__ . '<br />';
?>

Outputs something like this:

in test
/home/dev/test.php
in page
/home/dev/test/page.php
in page 2
/home/dev/test/page2.php


But, is there a way to tell the php engine to use a specific directory as root to just avoid this in the future all together?

getcwd() (http://php.net/getcwd)/chdir() (http://php.net/chdir) might be useful to you.

Big-Pat
11-16-2007, 05:58 AM
Yes, it is..

Well then something odd is going on, because when I change it to the path relative to the original file it works fine.

barkermn01
11-16-2007, 01:07 PM
... what? How is it any less secure than having the functions in different files?

You're assuming that they have a huge list of functions, and that every function(or almost every function) isn't needed on every page.

That is incorrect.

1. Yes it is less secure coz they find one file they know how your site works

And i See your point Big-Pat if they can get to one file why not all well there is software on my servers tht a contnualy looking for hack if it finds one it Restarts the Security and kicks them out so it is just a time thing but not sure that all servers have that my server cost me a boom to get setup and that is just my house Windows one dont know if linux ones can support it

2. Yes i am asumming that coz if you are basing your Site around a functions file you going to use alot of fuctions coz just to make a login script i use 2 and that a small loginscript

3. Funny check out my site
htp://barkersmedia.co.uk
the menu at at the top is CSS And HTML index the bottom bits are PHP include() every link you click out uses the Include function and a $_GET['p']
When i first started building sites in this way it got verry hard working out why my include("../SQL/connect.php") Was not working i Removed the ../ Ad it worked i know orther waise i had to put the full address of include("http://barksmedia.co.uk/SQL/connect.php")
So i googled it and i got taled to all ways use the Index.php as a root file and the rest mus be located to the root file


Well then something odd is going on, because when I change it to the path relative to the original file it works fine.

Just to prove my point

aedrin
11-16-2007, 05:04 PM
I just lost a few brain cells.

It's not that hard to use punctuation and a spelling checker is it? (Not that I use a spelling checker)

cheat
11-17-2007, 05:45 AM
if you think that it is a error then put mysql_error() at the top of your PHP and any errors will display on page.

Inigoesdr
11-17-2007, 06:05 AM
1. Yes it is less secure coz they find one file they know how your site works
If they simply find the file they know... nothing. Since simply declaring the functions wouldn't output anything. If they had access to your folder then it doesn't matter how many function files you have, or how you have them split up, they would know far more about your site than the functions would tell them.

barkermn01
11-17-2007, 11:16 AM
If they simply find the file they know... nothing. Since simply declaring the functions wouldn't output anything. If they had access to your folder then it doesn't matter how many function files you have, or how you have them split up, they would know far more about your site than the functions would tell them.

Yes ok
But i Still do it my why anc have the config Require Once by the inded lol
but then i do Speshalize in Index containd sites



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum