2013-07-17 2 views
0

좋아요.이 내용으로 proxy.php라는 파일을 가지고 있는데, 그 중 어떤 형식이 값으로 채워져 제출되면 "if"체크 사실이되어야하고 명령을 실행해야하지만 문제가 있으며 값을 제출하더라도 "if"체크에 포함되지 않습니다. 명령을 "if"체크에서 제외하면 작동하지만 내부에서는 작동하지 않습니다.HTML 양식을 PHP로 제출

<html> 
<body> 

<br> 
<form action="proxy.php" method="post"> 


<br> 

Host Port 1: <input type="text" name="hport" /> 
Server Port 1: <input type="text" name="sport"/> 
<br> 
Host Port 2: <input type="text" name="hport2"/> 
Server Port 2: <input type="text" name="sport2"/> 

<br> 


<input type="submit" /> 
</form> 

</body> 
</html> 

<?php 
include('Net/SSH2.php'); 



$_POST["ip"]="iphere"; 
$_POST["pass"]="passhere"; 



$ssh = new Net_SSH2($_POST["ip"]); 
if (!$ssh->login('root', $_POST["pass"])) { 
    exit('Login Failed'); 
} 


if($_POST['hport1']){ 

echo $ssh->exec('ls'); 
echo $ssh->exec('screen -S Proxy1 -X quit'); 
echo $ssh->exec('Run these commands'); 
} 

if($_POST['hport2']){ 

echo $ssh->exec('ls'); 
echo $ssh->exec('screen -S Proxy2 -X quit'); 
echo $ssh->exec('Run these commands'); 
} 


echo $ssh->exec('exit'); 


?> 
+0

그것은 전체 문제가되지 않을 수도 있지만 양식의 입력은'hport'이다; 당신의 코드는'hport1'을 찾고 있습니다. – andrewsi

+0

그리고 양식을 제출할 때 $ _POST [ 'hport']의 값은 무엇입니까? – Axarydax

+0

PHP를 한동안 사용해 본 적이 없지만 사용할 수있는 기능은 없습니까? –

답변

0

값 $의 _POST [ 'hport1'] null로 할 수 있습니다. 변경해보십시오.

if($_POST['hport']){ 
     echo $ssh->exec('ls'); 
     echo $ssh->exec('screen -S Proxy1 -X quit'); 
     echo $ssh->exec('Run these commands'); 
} 

문제가 계속되면

, 용도는 isset ($ _ POST는 [ 'hport']) 가변 'hport'의 값인지의 여부를 확인하기 위해. 당신은 mannually에서 POST 값을 확인 읽을 수있는 형식으로 $ _POST 배열 값을 표시하기위한

<?php var_dump($_POST); ?> 

또는

<?php 
    echo '<pre>' . print_r($_POST) . '</pre>'; 
?> 

사용할 수 있습니다. 희망이 당신을 도울 것입니다.

+0

감사합니다. 네, 그게 문제였습니다. 그것은 단지 오타 였고 내가 고칠 때까지 일했습니다. 우리는 isset 함수가 필요하지 않았다. –

1

자세한 내용을 확인하기 위해 isset을 시도해 볼 수 있습니다.

if(isset($_POST['Name of field to check for'])){ 
////CODE HERE 
} 

대안은 양식이 제출 된 경우 확인하고 당신이 HTML에서 'hport'을 게시하고 있기 때문에 무언가

if(empty($_POST) === false){ 
///CODE HERE 
} 
0

사용 는 isset() 변수를 확인하는 PHP의 & 빈() 붙박이 기능 ..

if(isset($_POST['hport'] && !empty($_POST['hport'])){ 
echo $ssh->exec('ls'); 
echo $ssh->exec('screen -S Proxy1 -X quit'); 
echo $ssh->exec('Run these commands'); 
} 

if(isset($_POST['hport2'] && !empty($_POST['hport2'])){ 
echo $ssh->exec('ls'); 
echo $ssh->exec('screen -S Proxy2 -X quit'); 
echo $ssh->exec('Run these commands'); 
} 
관련 문제