2012-10-03 40 views
0

从主题本身来看,我该如何做到这一点?...我使用管道将输出从linux传输到Php。当在新标签/页面中重新加载时保留textarea上的信息

e.g

echo "<textarea cols='100' rows='20' readonly='readonly' style='resize:none;'>"; 

     $dev = stream_get_contents($pipes[1]); 

     echo $dev; 

     echo "</textarea>"; 

     fclose($pipes[1]); 

这里是我的形式。

<form method="post"> 
<input type="radio" name="cmd" value="./iodev scan">Scan<br /> 
<input type="radio" name="cmd" value="./monitor">Enable Monitoring<br /> 
<input type="submit" value="GO"> 
</form> 

现在,当我得到的数据,我需要在加载到一个新的标签页或者在页面重新加载它会坐在那里,不会消失它在textarea的保留。

感谢,

回答

0

你可以尝试像会哄你的textarea的名字东西textPipes

if (!isset($_POST['textPipes']) || empty($_POST['textPipes'])) { 
    $_POST['textPipes'] = stream_get_contents($pipes[1]); 
    fclose($pipes[1]); 
} 

echo "<textarea cols='100' rows='20' readonly='readonly' style='resize:none;' name='textPipes' >"; 
echo $_POST['textPipes']; 
echo "</textarea>"; 

*编辑! *基于

对你的要求,你也可以疮它在内存缓存

$mem = new Memcache(); 
$mem->connect("localhost",11211); 

#Identify current user 
$currentUser = "demic0de"; 

#Create Unique Key 
$key = $currentUser . sha1($pipes[1]); 

if(!$mem->get($key)) 
{ 
    #set value and expire every 10 mins 
    $mem->set($key,stream_get_contents($pipes[1]) ,null,600); 
    fclose($pipes[1]); 
} 


echo "<textarea cols='100' rows='20' readonly='readonly' style='resize:none;' name='textPipes' >"; 
echo $mem->get($key); 
echo "</textarea>"; 
+0

尝试过,但我仍然没有得到输出,当我在新页面中打开它? – demic0de

+0

我可以只是将输出存储在一个文件中,然后当它重新加载时,它会在该文件中查找并在textarea中将其回显出来?然后,当我再次扫描时,它将删除旧的文本文件并获取新的输出? – demic0de

+0

是的,它可以将它保存在一个文件中,但我认为最好的办法是将它保存在像memcache这样的缓存系统中......如果你已经安装了,并且我可以添加代码 – Baba

相关问题