dqwh1219 2013-11-12 21:44
浏览 29

在Javascript中显示PHP变量 - 安全点

Originally I had the following structure:

index.html file:

...
<script src="myfunctions.js" />
...

myfunctions.js file:

...
function one() {
....
}
function two() {
....
}
function three() {
....
}

That way I got over 2 500 lines of Javascirpt written but then I had to add a PHP variable to a function so I had to rename index.html to index.php, rename myfunctions.js to myfunctions.js.php and do the following changes:

index.php file:

...
<?php
    include("myfunctions.js.php");
?>
...

myfunctions.js.php file:

<script>
...
function one() {
....
}
function two() {
....
}
function three() {
....
}
function four() {
    var x = <?php echo $_conf['user_id'];?>
    console.log(x);
}
</script>

I have achieved my purpose of using PHP variable in JavaScript but I have noticed that the web page in the browser started to show all the included function, i.e. if in the first case when I was looking at the page with a debug tool or by saving that page on a disk I saw just some little JavaScript code contained in index.html but now looking at or saving the index.php file I see all the functions from myfunctions.js.php visible. Of course the visible content didn't change but the actual output got 2 500 lines longer. Would that be a security problem? Should I avoid this way of showing a PHP variable in JavaScript or I shouldn't be concern about it and leave it how it is?

My concern is that in the second case all my functions gets open so a malicious user can see all the server-side PHP scripts names and required parameters which gives more ways to attack.

  • 写回答

3条回答

  • dsaf415212 2013-11-12 21:45
    关注

    The PHP code is processed on the server so all anyone will see if the output of that PHP. So your PHP code is still hidden.

    If you're seeing PHP code in your HTML output then either your server is configured incorrectly or you have a syntax error which echo's out what you intend for the parser to process.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog