export variables inside php script

Discussion in 'PHP' started by nathan_nz, Nov 20, 2007.

  1. #1
    hi all..
    I want to get the environment variables in my php script.

    ie php exec('source /pth/to/var/file');

    where variable file contains variable list. like export Var1=Value1...

    I cant use Var1 inside my script even after sourcing it..

    Please tell whether I am going wrong or is there another method for it..

    Thanking you
     
    nathan_nz, Nov 20, 2007 IP
  2. phpl33t

    phpl33t Banned

    Messages:
    456
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Give this a gander. I think you are making it harder than it is, but then again, I don't know what env vars you are refering to.

    http://us.php.net/reserved.variables

    http://us3.php.net/getenv

    I hope this helps.


    Usually with the method I see you trying, you would use one of these instead:

    include($file);
    include_once($file);
    require($file);
    require_once($file);

    But not for env vars.
     
    phpl33t, Nov 20, 2007 IP
  3. nathan_nz

    nathan_nz Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the reply.

    my file looks like

    export Var=Value.

    In shell scripts we 'source' the file and use $Var in the script.
    Cant we do the same in php.
     
    nathan_nz, Nov 20, 2007 IP