2016-11-23 35 views
-2

我需要你的幫助。 Atm Im編寫一個php腳本,它可以從HTML輸入框中將單個文本輸入寫入文本文件。繼承人的代碼:使用按鈕將值傳輸到文本文件中php

<center> 
    <form name="form" action="" method="get"> 
     <input type="text" name="APIkey" id="APIkey" value="API Key"> 
    </form> 
</center> 

該網站的用戶需要輸入APIkey到文本框中,然後他應該按一個按鈕APIkey轉移到下面的PHP腳本將它寫在APIkey.txt

<?php 
$myfile = fopen("APIkey.txt", "w") or die("Unable to open file!"); 
$txt = APIkey; 
fwrite($myfile, $txt); 
fclose($myfile); 
?> 

感謝您的幫助......

+1

您可以使用AJAX方法發送API給定的代碼。 – Elby

回答

0

你需要做一些改變你的代碼,使之按您的requirements.Create工作的文本文件在你的PHP文件的同一目錄下。簡單的方法是低於

<center> 
    <form name="form" action="" method="post"> 
    <input type="text" name="APIkey" id="APIkey" value="API Key"> 
    <input type="submit" value="submit" name="submit" > 
    </form> 
</center> 

<?php 
if(isset($_POST['submit'])) 
{ 
    $myfile = fopen("APIkey.txt", "w") or die("Unable to open file!"); 
    $txt = $_REQUEST['APIkey']; 
    fwrite($myfile, $txt); 
    fclose($myfile); 
} 
?> 
+0

謝謝你非常有幫助 –

+0

如果它有幫助,你可以作爲有益的答案 –

0

我認爲是時候閱讀關於PHP請求的好教程。 https://www.tutorialspoint.com/php/php_get_post.htm

<form name="form" action="" method="get"> 
    <input type="text" name="APIkey" id="APIkey" value="API Key"> 
</form> 

您有GET方法發送您的數據,但很長一段文本它不建議報告通過URL

通過
<form name="form" action="" method="post"> 
    <input type="text" name="APIkey" id="APIkey" value="API Key"> 
</form> 

    <?php 

    // For information 
    var_dump($_POST); 

    if(isset($_POST["APIkey"]) { 

    $myfile = fopen("APIkey.txt", "w") or die("Unable to open file!"); 
    $txt = $_POST["APIkey"]; 
    fwrite($myfile, $txt); 
    fclose($myfile); 

    } 
?> 
+0

是的,讓所有發送敏感信息像apikeys GET請求^^ – RFLdev

相關問題