简体   繁体   English

PHP:如何在JS中打开新窗口并从PHP中回显

[英]PHP: How to open a new window in JS and echo from PHP into it

for debugging I reasons I use very often PHP function var_dump() 进行调试,原因是我经常使用PHP函数var_dump()

<pre>
  <?php
    var_dump($myVariablesArray);
  ?>
</pre>

but I need to output its contents (and something more I use for my debugging) into a new popup window. 但是我需要将其内容(以及更多用于调试的内容)输出到新的弹出窗口中。

There are several examples about opening a new JS window, but I cannot find anything helping me opening a new window and printing from PHP into it, all this automatically when the page I'm debugging is loaded. 有几个有关打开新JS窗口的示例,但是我找不到任何帮助我打开新窗口并从PHP打印到其中的信息,所有这些在加载调试页面时自动完成。

Any hint? 有什么提示吗?

you could var_export() instead maybe. 您可以var_export() And then append it to the beginning of a txt on the server. 然后将其附加到服务器上txt的开头。 Then you can have a little script in the second window that refreshes every 5 seconds, and shows that txt file. 然后,您可以在第二个窗口中有一个小脚本,该脚本每5秒刷新一次,并显示该txt文件。 Much like a log . 很像日志

http://www.php.net/manual/en/function.var-export.php http://www.php.net/manual/zh/function.var-export.php

pro: you can keep the txt between runs, and save the outputs. 专家:您可以在两次运行之间保留txt,并保存输出。

con: the format is a bit different than var_dump() 缺点:格式与var_dump()略有不同

I solved the problem thanks to suggestion on Add content to a new open window 我解决了这个问题,这要归功于有关向新打开的窗口添加内容的建议

On the page I want to debug, where I need to, I add following code (if session is not started I need to add "session_start();" ): 在需要调试的页面上,添加以下代码(如果会话未启动,则需要添加“ session_start();”):

<?php
$_SESSION['varsLog'] = "<pre>".htmlspecialchars(print_r($myVariablesArray))."</pre>\n";
?>
<script type="text/javascript">
$(document).ready(function () {
var OpenWindow = window.open("/empty.html", "phpLog", 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=1400,height=640');
});
</script>

and then I have the empty.html page on the root of my domain: 然后在域的根目录下有empty.html页面:

<?php session_start(); if (!isset($_SESSION['varsLog'])) { exit(1); } ?>
<html><body>
<?php
echo date(DATE_RFC822); 
$refer = $_SERVER['HTTP_REFERER'];
echo "<br><br>Variables from <a href=".$refer.">".$refer."</a><br><br>";
echo $_SESSION['varsLog'];
unset($_SESSION['varsLog']);
?>
</body></html>

This way I can add the first code snippet to any page I need to debug, every time I load those pages the new window I previously opened will be just updated with the variables from the last page loaded, with a useful referring url and time stamp to be sure. 这样,我可以将第一个代码段添加到我需要调试的任何页面上,每次加载这些页面时,我先前打开的新窗口将使用最后加载的页面中的变量进行更新,并带有有用的引用url和时间戳为了确定。

Thanks for help to everyone! 感谢大家的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM