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 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3