我有一個頁面http://www.mysite.com/newsletter.php如何在用戶訪問後使頁面過期?
現在我想提出一個變量那裏,當我向您發送電子郵件,你訪問這個頁面看到你的電子郵件/用戶名存在。
所以我向您發送電子郵件此鏈接http://www.mysite.com/[email protected]
現在,當你將訪問此鏈接,您將看到您Email /用戶名在該網頁爲「你好[email protected],看看新博客」
上我寫與
<?php echo $_GET['user']; ?>
現在頁面上的用戶名/電子郵件,我如何才能讓這個頁面過期您訪問之後呢?我的意思是我只想訪問它一次!
* EDITED
看我使用已經生成到期唯一鏈接代碼:
<?php
include("variables.php");
$password = trim($_SERVER['QUERY_STRING']);
if($password == ADMIN_PASSWORD) {
$new = uniqid('key',TRUE);
if(!is_dir('keys')) {
mkdir('keys');
$file = fopen('keys/.htaccess','w');
fwrite($file,"Order allow,deny\nDeny from all");
fclose($file);
}
$file = fopen('keys/keys','a');
fwrite($file,"{$new}\n");
fclose($file);
?>
<html>
<head>
<title>Page created</title>
<style>
nl {
font-family: monospace
}
</style>
</head>
<body>
<h1>Page key created</h1>
Your new single-use page link:<br>
<nl>
<?php
echo "http://" . $_SERVER['HTTP_HOST'] . DOWNLOAD_PATH . "?" . $new;
?></nl>
</body>
</html>
<?php
} else {
header("HTTP/1.0 404 Not Found");
}
?>`
而且該碼在36個小時內過期,由variables.php設置
<?
define('PROTECTED_DOWNLOAD','download.php');
define('DOWNLOAD_PATH','/.work/page.php');
define('SUGGESTED_FILENAME','download-doc.php');
define('ADMIN_PASSWORD','1234');
define('EXPIRATION_DATE', '+36 hours');
header("Cache-Control: no-cache, must-revalidate");
header("Expires: ".date('U', strtotime(EXPIRATION_DATE)));
?>
這個php文件生成一個這樣的鏈接:http://www.mysite.com/page.php?key1234567890 現在如何添加t他在uniqid旁邊變量[email protected]生成這樣的鏈接:page.php?key1234567890 & [email protected]可以通過<?php echo $_GET['user']; ?>
在下一頁獲得[email protected]。
對不起,我的英語不好。
這樣的選項,你可以幫我一個例子嗎?我不是一個好的編碼員,我仍然在學習!這可以做到沒有數據庫?也許cookies或uniqid? – Iulius
不是,我認爲這很簡單。請分享一些代碼,你到目前爲止,我會很樂意幫你完成它 –
看看,檢查這個http://stackoverflow.com/questions/19411656/single-use-download-script-modification和這個http:// stackoverflow.com/questions/19395203/add-a-variable-that-will-be-echo-on-page-next-to-uniqid – Iulius