如何使用 PHP 获取 document.location.href 的值


How to get the value of document.location.href with PHP

我需要捕获JavaScript代码的值。更准确地说是document.location.href,但我需要使用PHP来做到这一点。

实际上我正在这样做:

$html = file_get_html("http://server.camgate.ru/snapshot.php?camid=111013191059");
       $element = $html->find('img'); 
       $img =  $element->src;

它显示了进度.gif,这很酷,问题是我需要在该网页内获取JavaScript的href以显示内部的图像。

喜欢这个:

$url = "http://server.camgate.ru/snapshot.php?camid=111013191059";
$html = file_get_html($url);
       $element = $html->find('script'); 
       $link =  $element->href;
       $data[]   = array("camara" =>"Camara 1", "imagen"=>$link);

$html显示了这一点:

<script>  'n    width=document.body.clientWidth;  'ndocument.location.href = '"http:'/'/camgate.ru'/showpix.php?id=111013191059&m=1013&d=171013&pix=171013035306.jpg'";      'n<'/script>

所以我需要在那里发布网址。但是如果我使用 $element->href,它会显示空。

我怎样才能得到它?

提前致谢

你可以用PHP绘制Javascript,但你不能反过来。如果您需要将数据传回PHP,唯一的方法是使用AJAX。要么这样,要么事先弄清楚 PHP 端的 URL 端。