Is super global the answer?

Discussion in 'PHP' started by jacka, Apr 30, 2008.

  1. #1
    Hi

    I have a simple problem.
    I want to set value of a variable and use it in several php scripts in my site to access it.
    Can you please advise me the best way to go.
    thanks for your time.
    :confused::D
     
    jacka, Apr 30, 2008 IP
  2. Altari

    Altari Peon

    Messages:
    188
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Will all scripts be using the same login? Maybe a session variable would be the better way to go in that case.
     
    Altari, Apr 30, 2008 IP
  3. jacka

    jacka Peon

    Messages:
    165
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi
    This variable is carriage charge and is constant and may not change from one year to next.
    The scripts do use the same database and several tables.

    I am sorry if I am not too clear as I am fairly new to php.

    So, just to sum up, I use this carriage charge on many pages and instead of going and manually changing them in 10 or so different places I thought it might be handy if I could write it once and refer to it in all occasions.
    thx
     
    jacka, Apr 30, 2008 IP
  4. Altari

    Altari Peon

    Messages:
    188
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    OK. You're not looking for a super global. Your best bet (IMO) would be to create a single php page called global_variables or something similar, define them in that page, and include the page in all other pages via the header or connect file.
     
    Altari, Apr 30, 2008 IP
  5. jacka

    jacka Peon

    Messages:
    165
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi Altari
    Many thanks for your advice.
    Could you please tell me the commands I need to look up to learn more about using variables using "header" and "connect file" or do you mean using the command "include"?
    Thanks
    jacka:confused::D
     
    jacka, May 1, 2008 IP
  6. roshanbh

    roshanbh Peon

    Messages:
    52
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    well, I think you can only get solution by storing the value in database....
     
    roshanbh, May 1, 2008 IP
  7. Randombase

    Randombase Peon

    Messages:
    224
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Or just use the common method of using a config file, like:
    <?php
    $specialvariable = 'special value';
    ?>
    PHP:
    And include it in every file by using:
    <?php
    include_once('path/to/config.php');
    /*
    rest of the code goes here
    */
    ?>
    
    PHP:
     
    Randombase, May 1, 2008 IP
  8. jacka

    jacka Peon

    Messages:
    165
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Hi
    Thanks for your comments.
    Does this have to be named config or can I call it any name I like.
    What I am really asking is, is there any thing significant about the config file?
    thx jacka
    :D
     
    jacka, May 1, 2008 IP
  9. hendrawan

    hendrawan Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I think you can named it anything you like, as long as you included it in every script.
     
    hendrawan, May 1, 2008 IP
  10. jacka

    jacka Peon

    Messages:
    165
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Thanks for that.
    Its so simple even I can follow it.
    Cheers all:eek:
     
    jacka, May 1, 2008 IP
  11. Altari

    Altari Peon

    Messages:
    188
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #11
    There's nothing significant. It's a good practice to make it meaningful, though. If you have a bunch of different scripts running, calling it "config.php" will be more than a little ambiguous, so make sure the name means something to you. Good luck. =)
     
    Altari, May 1, 2008 IP