年度更改时的PHP日期问题

时间:2017-02-23 23:14:08

标签: php date

我是PHP和一般代码的新手,所以请原谅任何邋!! ......

我在此处所做的是一个过期的链接工具,因此有人可以让他们的链接在特定日期($getdate)过期。

如果此人在$getdate之前点击了该链接,那么他们就会被转移到$goodurl

如果此人点击$getdate之后的链接,则会将其传递到$ expired网址。

示例网址为:https://expiring.click/?d=02/24/2017&g=https://example.com/deal/&e=https://example.com/no-deal/

希望这是有道理的。

现在,这个代码只有一个例外......当前年份与到期年份不同。

当发生这种情况时,人们总是被发送到$goodurl

所以,如果我的链接设置在2016年2月2日到期,我今天点击它(02/23/2017)......我会看到$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)){
	if ($sentdate < $date){ //expired
		if (empty($expiredurl)) {
			$link = "https://expiring.click/?expired=y";
		} else {
			$link = $expiredurl;
		}
	} else if ($sentdate >= $date){ //in date
		$link = $goodurl;
	}
	header( 'Location: '.$link ) ;
} else if ($expired == "y") {
	echo "Sorry, this link has expired.";
} else {
	?>
&#13;
&#13;
&#13;

0 个答案:

没有答案