【发布时间】:2015-09-10 17:53:22
【问题描述】:
我需要能够在表单中输入 IP 地址,然后该 IP 将用于获取在 http://'IP':port/status.php 上运行的 status.php 页面,然后显示表格下方的内容。
我附上了我拥有的两个 index.php 和 status.php 文件。他们在 zend 之外工作。
我将如何使用 zend 1.12 做到这一点?
status.php
<?php
/*error_log(date("U").": ".implode(", ",array_keys(($_REQUEST)))."\n",3,"/tmp/phperror.log");
if(!isset($_REQUEST['ip']))
exit(0);
*/
$ip = $_POST['IP'];
function getIP($ip)
{
$port = ( $_REQUEST[ 'port' ] != "" ? $_REQUEST[ 'port' ] : '1234' );
$site='http://'.$ip.':'.$port.'/status.php';
//foreach( $_REQUEST as $k => $v)
if ( $_REQUEST[ 'mode' ] != 'json' ) {
//error_log(date("U").": ".$site." : ".implode($_REQUEST)."\n",3,"/tmp/phperror.log");
error_log( date( "U" ) . ": " . $site . " : " . implode( ", ", array_keys( ( $_REQUEST ) ) ) . "\n", 3, "/tmp/phperror.log" );
$file = file_get_contents( $site, false, $context );
echo $file;
}
else {
if ( $_SERVER[ 'REQUEST_METHOD' ] == 'POST' ) {
$r = $site . "?d=v";
$data = array();
foreach ( $_REQUEST as $key => $value ) {
$r .= "&$key=$value";
$data[ $key ] = $value;
}
$options = array( 'http' => array(
'method' => 'POST',
'content' => http_build_query( $data )
) );
error_log( date( "U" ) . ": " . $r . "\n", 3, "/tmp/phperror.log" );
$context = stream_context_create( $options );
//$file = file_get_contents($r, false, $context);
$file = file_get_contents( $site, false, $context );
echo $file;
}
}
}
getIP($ip);
?>
索引。 php
<!DOCTYPE html>
<html lang="en">
<head>
<title>Title</title>
<meta charset="UTF-8">
<meta name=description content="">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" media="screen">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<h1 class="text-center">IP Address</h1>
<form action="status.php" method="post" role="form" class="form-horizontal">
<div class="form-group">
<label for="IP" class="col-sm-2 control-label">Enter IP Address</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="IP" id="IP" placeholder="IP Address">
</div>
</div>
<button type="button" class="btn btn-primary" onclick="deleteFile()">Submit</button>
<button type="reset" class="btn btn-danger">Clear</button>
</form>
</div>
<div id="section"></div>
</div>
</div>
<!-- jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Bootstrap JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script>
/* Deletes the selected file */
function deleteFile() {
$.ajax({
type: "POST",
url: "status.php",
data: {
IP: $( "#IP" ).val()
}
})
.success(function (data) {
$('#section').html(data);
});
}
</script>
</body>
编辑:
我按照 Lucian 的步骤进行操作,但我认为我的控制器上的 indexaction 不正确。
我在那里粘贴了 status.php 并且它的错误....我有什么错误
indexcontroller.php
<?php
class IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
/*error_log(date("U").": ".implode(", ",array_keys(($_REQUEST)))."\n",3,"/tmp/phperror.log");
if(!isset($_REQUEST['ip']))
exit(0);
*/
$ip = $_POST['IP'];
function getIP($ip)
{
$port = ( $_REQUEST[ 'port' ] != "" ? $_REQUEST[ 'port' ] : '1234' );
$site='http://'.$ip.':'.$port.'/status.php';
//foreach( $_REQUEST as $k => $v)
if ( $_REQUEST[ 'mode' ] != 'json' ) {
//error_log(date("U").": ".$site." : ".implode($_REQUEST)."\n",3,"/tmp/phperror.log");
error_log( date( "U" ) . ": " . $site . " : " . implode( ", ", array_keys( ( $_REQUEST ) ) ) . "\n", 3, "/tmp/phperror.log" );
$file = file_get_contents( $site, false, $context );
echo $file;
}
else {
if ( $_SERVER[ 'REQUEST_METHOD' ] == 'POST' ) {
$r = $site . "?d=v";
$data = array();
foreach ( $_REQUEST as $key => $value ) {
$r .= "&$key=$value";
$data[ $key ] = $value;
}
$options = array( 'http' => array(
'method' => 'POST',
'content' => http_build_query( $data )
) );
error_log( date( "U" ) . ": " . $r . "\n", 3, "/tmp/phperror.log" );
$context = stream_context_create( $options );
//$file = file_get_contents($r, false, $context);
$file = file_get_contents( $site, false, $context );
echo $file;
}
}
}
getIP($ip);
?>
}
【问题讨论】:
-
Zend 有什么问题?
-
是什么让你认为它在 zend 中不起作用?
-
我以前从未使用过它,所以我不知道我会添加什么以及使用什么语法。
标签: php zend-framework