2016-11-30 2 views
-1

로드 페이지로 이동 한 다음 powershell 스크립트를 실행하려고합니다. 하지만 불행히도 나는 이것을 작동시킬 수 없다. 제가 페이지에 가면 자동으로 스크립트로 가서 실패 페이지의 성공으로 리디렉션합니다. 리디렉션 후 절전 모드를 시도했지만 몇 초 정도 기다렸다가 스크립트를 실행하고 html 페이지로 리디렉션합니다.리디렉션을 한 다음 실행

 header('Location: /loading.html'); 
     include ("file\where\the\variable\comes\from.php"); 
     $s = shell_exec("powershell path\\to\\script.ps1 '$variable'< NUL"); 

     if (strpos($s, 'True') === false) { 
     header('Location: /succes.html'); 
     } 
     else{ 
     header('Location: /failed.html'); 
     } 
+0

당신이 놓치고있는'출구(); '. 스크립트는 리디렉션 할 필요가 있지만 알 수없는 끝 때문에 계속할 수 없으므로 첫 번째'header()'에서 죽어 가고 있습니다. 로드 페이지를'include()'또는'require_once()'한 다음 각'header()'메소드 다음에'exit();'를 추가하십시오. [여기에 어떻게 있어야하는지 알아보십시오.] – KDOT

+0

왜 리디렉션을 먼저 사용하고 쉘 스크립트에서 리디렉션 한 후에 만 ​​사용해야합니까? 내가 아는 한, 여기서 일어나는 일은 다음과 같습니다. 1. 서버가 브라우저로 리디렉션 헤더를 전송합니다. (코드의 첫 번째 줄) 2. 브라우저에서 loading.html을 묻습니다. 3. 서버가 loading.html을 브라우저로 보냅니다. 나머지 스크립트는 실행되지 않습니다. – Dragos

답변

1

파일로드가 완료 될 때 페이지가 표시되기 때문에 로딩 페이지를 작성할 수 없습니다. AJAX 요청을 통해 include/shell을 실행하면됩니다. 아래 해결책은 AJAX 요청을 request.php 파일로 실행하고 그의 내용을 loading.html의 내용으로 복사하는 색인 ​​페이지 (loading.html)입니다.

loading.html

<!-- Your loading.html content ---> 

<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script> 
<script type="text/javascript"> 
$.post("request.php", function(data) { 
    $("body").html(data); 
}); 
</script> 

request.php

include ("file\where\the\variable\comes\from.php"); 
$s = shell_exec("powershell path\\to\\script.ps1 '$variable'< NUL"); 

if (strpos($s, 'True') === false) { 
    echo file_get_contents('succes.html'); 
} 
else { 
    echo file_get_contents('failed.html'); 
} 
+0

감사합니다. 완벽하게 작동했습니다. 유일한 문제는 내 서버가 아직 인터넷에 액세스 할 수 없다는 것이 었으므로 jquery 스크립트를 로컬에 배치했습니다. –