Print value of javascript in php

两盒软妹~` 提交于 2019-12-13 07:20:28

问题


I need to code something like that to print value of javascript in php

<?php

$url = ( Value of <script>document.write(top.location.href);</script> );

echo ''.$url.'';

?>

Update: I need this to break frames, block proxy websites and bots so $_SERVER not useful

Please can anyone help me ?

Thank you


回答1:


No, that's not possible because PHP (server-side) is run before javascript (client side) code. You can do the opposite though. You will have to resort to one of these:

  • AJAX
  • Hidden Field
  • Query String

Though, if you want to read the current page URL, you could use:

$_SERVER['REQUEST_URI']



回答2:


To do what you're doing in PHP you could do $url = $_SERVER['PHP_SELF'];




回答3:


you might not be looking at this the right way. you can see the current path in the url by looking at this variable

echo $_SERVER['REQUEST_URI'];

Read More

Update:

Since you want to prevent your site for being under an iframe, you can google frame busting script, it is done entirely in javascript.



来源:https://stackoverflow.com/questions/10485988/print-value-of-javascript-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!