2017-02-23 26 views
0

我與一般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 ?>

回答

0

你必須使用兩個發送日期和日期的strtotime()funtion後比較。

$ sentdate = date(「m/d/Y」,strtotime($ getdate));

應該是

$sentdate = strtotime(date("m/d/Y", strtotime($getdate))); 

而且 $日期=日期( 'M/d/Y');

應該

$date = strtotime(date('m/d/Y')); 
+0

你搖滾的人,謝謝! – Nathan

+0

歡迎........... :) –