I need the ability to enter an IP address in a form and then that IP would be used to obtain a status.php page that is running on http://'IP':port/status.php and then display the contents below the form.
I attached the two index.php and status.php files I have. They work outside of zend.
How would I do this with 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);
?>
index. 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>
EDIT:
I followed Lucian's steps and I believe I do not have my indexaction on the controller correct.
I pasted status.php there and its erroring.... What do I have wrong
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);
?>
}