2016-02-12 69 views
1

我的網站爲每個帳戶生成一個唯一的密鑰(密碼)來登錄。這是重要的,保密的,不可恢復的。那麼,如何讓每個人都可以下載txt文件。如何讓div內容下載到txt文件?

此代碼:

echo '<h2>'; 
print "Welcome $username to your dashboard<br>"; 

} 
echo "</h2>"; 
echo "<p>"; 

$sec_value = 'usqi3289'; 
$rdecrypted_text = mcrypt_ecb(MCRYPT_DES, $sec_value, $userkey, MCRYPT_DECRYPT); 

echo "<div class='button special'>Your Userkey: <font color='black'>$rdecrypted_text</font></div>"; 
?> 
<br><p align="center">Please save your Userkey first,This is confidential and unrecoverable, because we don't hold any passwords. </p> 

主要是這一個:

"<div class='button special'>Your Userkey: <font color='black'>$rdecrypted_text</font></div>"; ?> 

我要低於一個按鈕,所以人們點擊它,它下載包含這個userkey一個txt文件。

+0

你可以使用HTML創建按鈕,並綁定事件點擊它使用javascrit/jQuery例如? – Vnuuk

+0

我不太確定這個,但我可以在下面添加一個按鈕,但它應該連接$ rdecrypted_text – user3265050

+0

這很好。然後在點擊事件中,您可以向服務器發送ajax請求並獲取txt文件? – Vnuuk

回答

1

您可以將此代碼放入PHP file,例如, userkeydl.php

<?php 

    header("Content-type: text/plain"); 
    header("Content-Disposition: attachment; filename = userkey.txt"); 

    print "Your Userkey is: \n"; 
    print $rdecrypted_text; 
    print "\nPlease note that this is confidential and unrecoverable."; 

?> 
+0

我們也會尋找替代品,比如將div內容下載到txt文件 – user3265050

+0

@ user3265050您可以在'txt'文件中打印'div'內容 – Panda