How to store variable in one php file and access in other php file

Discussion in 'PHP' started by globalcashsite, Dec 20, 2009.

  1. #1
    Guys

    I want to create configure.php file where I can set different variables related to my new small module. I wish I store here my site's variable name and access this variable in all other files so if I change my site name in configure.php it may change at all places.

    I am doing this in configure.php

    $sitename = "GlobalCashSite";

    And then I added configure.php in all php pages. For example at signup.php I am doing following:

    require "config.inc.php";
    print $sitename;

    But script is not printing $sitename. Please help me what I am missing in this. My global_variable is off and I want to keep this off.


    GCS
     
    globalcashsite, Dec 20, 2009 IP
  2. pubdomainshost.com

    pubdomainshost.com Peon

    Messages:
    1,277
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you are storing variables in config.php and require config.inc.php there is a biggggg problem.
    Make sure you include the correct filename, then only it would work.
     
    pubdomainshost.com, Dec 20, 2009 IP
  3. globalcashsite

    globalcashsite Peon

    Messages:
    806
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi buddy

    That is not a problem, my correct file name is config.inc.php and I am using it correctly in files. Thanks for pointing it. :)

    GCS
     
    globalcashsite, Dec 20, 2009 IP
  4. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #4
    As long as

    $sitename = "GlobalCashSite"; is in the file config.inc.php try.

    <?php include "config.inc.php";?>

    And echo instead.

    <?php echo $sitename;?> where you need it on your pages
     
    MyVodaFone, Dec 21, 2009 IP
  5. minervait

    minervait Peon

    Messages:
    85
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    use Session Variable for best use
     
    minervait, Dec 21, 2009 IP
  6. saiyeek

    saiyeek Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I recommend use of define() for site-wide use of constants like sitename .
     
    saiyeek, Dec 21, 2009 IP
  7. masterofweb

    masterofweb Greenhorn

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #7
    u can use session variable .....
    enter a value in session variable and get any page
     
    masterofweb, Dec 21, 2009 IP
  8. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #8
    define is definitely the way to go
     
    JAY6390, Dec 21, 2009 IP