Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    34
    Thanks
    2
    Thanked 1 Time in 1 Post

    Config File Include anf Functions

    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?

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,036
    Thanks
    2
    Thanked 316 Times in 308 Posts
    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.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Is there a reason this doesn't work?(I'm not getting any errors.)
    So how do you know it's not working?

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,036
    Thanks
    2
    Thanked 316 Times in 308 Posts
    Good question.

    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. <--- Could not find a sarcastic smiley, so he will have to do.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    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.

  • #6
    New Coder
    Join Date
    May 2006
    Posts
    34
    Thanks
    2
    Thanked 1 Time in 1 Post
    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?

  • #7
    New Coder
    Join Date
    May 2006
    Posts
    34
    Thanks
    2
    Thanked 1 Time in 1 Post
    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.

  • #8
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    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?

  • #9
    New Coder
    Join Date
    May 2006
    Posts
    34
    Thanks
    2
    Thanked 1 Time in 1 Post
    Well I assume, it's because there's nothing in them. And just to clarify, I mean any that are assigned in config.php
    Last edited by Big-Pat; 11-15-2007 at 09:52 PM. Reason: Clarity

  • #10
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,036
    Thanks
    2
    Thanked 316 Times in 308 Posts
    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.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #11
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    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().

  • #12
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts
    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
    Code:
    Page one index.php
    
    include("file/this.php")
    Code:
    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

  • Users who have thanked barkermn01 for this post:

    Big-Pat (11-16-2007)

  • #13
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by barkermn01 View Post
    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?
    Quote Originally Posted by barkermn01 View Post
    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.
    Quote Originally Posted by barkermn01 View Post
    second if you are ding this
    Code:
    Page one index.php
    
    include("file/this.php")
    Code:
    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.

  • #14
    New Coder
    Join Date
    May 2006
    Posts
    34
    Thanks
    2
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Inigoesdr View Post
    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?

    Quote Originally Posted by barkermn01 View Post
    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.

  • #15
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by Big-Pat View Post
    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.
    Quote Originally Posted by http://php.net/include
    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 Code:
    <?php
    echo 'in test<br />';
    echo 
    __FILE__ '<br />';
    include(
    'test/page.php');
    ?>
    test/page.php
    PHP Code:
    <?php
    echo 'in page<br />';
    echo 
    __FILE__ '<br />';
    include(
    'page2.php');
    ?>
    test/page2.php
    PHP Code:
    <?php
    echo 'in page2<br />';
    echo 
    __FILE__ '<br />';
    ?>
    Outputs something like this:
    Code:
    in test
    /home/dev/test.php
    in page
    /home/dev/test/page.php
    in page 2
    /home/dev/test/page2.php
    Quote Originally Posted by Big-Pat View Post
    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()/chdir() might be useful to you.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •