我與一般PHP
和代碼對於新手,所以請原諒任何草率發行日期......PHP時的增減幅度
我在這裏做的是即將到期的鏈接工具,以便有人能做出自己的鏈接過期某個日期($getdate
)。
如果此人在點擊$getdate
之前的鏈接,那麼他們將被傳遞到$goodurl
。
如果此人在點擊$getdate
之後的鏈接,那麼他們將被傳遞到$ expired url。
一個例子網址是:https://expiring.click/?d=02/24/2017&g=https://example.com/deal/&e=https://example.com/no-deal/
希望這有一定的道理。
現在,此代碼與一個例外一起工作...當今年與過期年不同時。
發生這種情況時,人們總是被髮送到$goodurl
。因此,如果我的鏈接設置爲在02/02/2016到期,我今天點擊它(2017年2月23日)...我會看到$goodurl
即使到期日期是一年多。
我想不出來拯救我的生命。
希望你們中的一位好人能幫上忙!
感謝。
<?php
$getdate = htmlspecialchars($_GET["d"]); // Date Good Through
$sentdate = date("m/d/Y", strtotime($getdate)); // Make sure date is in correct format
$goodurl = htmlspecialchars($_GET["g"]); // Good URL
$expiredurl = htmlspecialchars($_GET["e"]); // Expired URL
$expired = htmlspecialchars($_GET["expired"]); // For Expired = y
// Date Stuff
date_default_timezone_set('America/New_York');
$date = date('m/d/Y');
$datetime = date('m/d/Y h:i:s a', time());
$tomorrow = date('m/d/Y',strtotime($date . "+1 days"));
// Formula Stuff
if ($expired != "y" && !empty($getdate)){
\t if ($sentdate < $date){ //expired
\t \t if (empty($expiredurl)) {
\t \t \t $link = "https://expiring.click/?expired=y";
\t \t } else {
\t \t \t $link = $expiredurl;
\t \t }
\t } else if ($sentdate >= $date){ //in date
\t \t $link = $goodurl;
\t }
\t header('Location: '.$link) ;
} else if ($expired == "y") {
\t echo "Sorry, this link has expired.";
} else {
\t ?>
你搖滾的人,謝謝! – Nathan
歡迎........... :) –