doudong0425 2016-09-27 08:53
浏览 93
已采纳

Php,如何在内存中“注入”变量(和值)

I'm looking for a way to :

  1. define a php global variable:

    • If a execute a php file A, file B ... I can access this variable while apache is running.
  2. 'hide' the value of this variable

    • I don't want the value of this variable be findable if someone access to the server and search (via a grep -nri by example) the value of this variable in a PHP file

My question is:

  • Is there a way for inject a global persistent (while Apache running) variable in memory without define its value in any file in the server ?

=> if I create a simple PHP form where the user can set and submit the value of this variable, how can I save the value of this variable for it can be accessible from any PHP file ?

Question bonus:

  • Is there a way for inject an usable PHP variable via a C or JAVA program ? (via a compiled program)
  • 写回答

1条回答 默认 最新

  • dpzjl68484 2016-09-27 09:02
    关注

    in your PHP script and/or program. If you can do it in .htacces, you can do it in your vhost configuration.

    echo $_SERVER['MY_VAR']
    

    There's also PHP functions to set your PHP ini values.

    In your first file

    <?php
    $uniqid="Hello";
    putenv("UNIQID=$uniqid");
    ?>
    

    In your second file

    <?php echo getenv('UNIQID') ?>
    

    I'm not sure about a way to populate $ENV, or is SetEnv will do it. It's worth investigating a var_dump($ENV) with the above.

    Inject PHP variable into JAVA

    Process runtime = Runtime.getRuntime().exec("php -r  'echo getenv(\'UNIQID\');'");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 win c++ socket
  • ¥15 CanMv K210开发板实现功能
  • ¥15 C# datagridview 栏位进度
  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web
  • ¥15 kali环境运行volatility分析android内存文件,缺profile
  • ¥15 写uniapp时遇到的问题
  • ¥15 vs 2008 安装遇到问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的