PHP-在url中插入日期


PHP - Insert date to url

我有一个联系表格,在用户提交表格后,我希望它重定向到我们的推广页面,我知道如何在提交表格后进行重定向,但我需要自动将日期(月/日/年)插入到url,如:http://myshop.com/promotion/index.php?from=September/dateoftomorrow/2014&至=2014年9月/日之后

有可能使用php来实现吗?如果可以的话,你能指导我怎么做吗?非常感谢:)

以便将日期传递到下一页。使用strtotime()函数将日期转换为等效的时间戳。

$url = "http://myshop.com/promotion/index.php?from=".strtotime('September/dateoftomorrow/2014')."&to=".strtotime('September/dateaftertomorrow/2014')

如果您需要URL中的日期,请尝试使用urlender()函数在URL中编码日期

$url = "http://myshop.com/promotion/index.php?from=".urlencode('September/dateoftomorrow/2014')."&to=".urlencode('September/dateaftertomorrow/2014')

您需要这样的东西:

<?php
// get the timestamp of tomorrow
$tomorrow = strtotime('+ 1 day');
// get the timestamp of the day after tomorrow
$after_tomorrow = strtotime('+ 2 day');
// the format we build the date in
$format = 'F/d/Y';
// get the tomorrow date in the specified format
$from = date($format, $tomorrow);
// get the day after tomorrow date in the specified format
$to = date($format, $after_tomorrow);
// build the URL
$url = 'http://myshop.com/promotion/index.php';
$url .= '?from=' . $from;
$url .= '&to=' . $to;
// redirect to the URL
header("Location: " . $url);
exit;
?>

您可以编写header("位置:http://redirect-name.com?to=".$mm/".$dd."/".$yy);

在您的情况下,如果您想重用当前路径,可能需要使用$_SERVER['REQUEST_URI']