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\');'");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作