问题
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