编写脚本电脑怎么编写界面_编写“您最后一次访问”PHP脚本

编写脚本电脑怎么编写界面

完整代码 ( The Full Code )

More information about how this script works, and what each section does is on the following pages.

有关此脚本如何工作以及每个部分的作用的更多信息,请参见以下页面。

设置和检索Cookie ( Setting and Retrieving the Cookie )


<?php if(isset($_COOKIE['AboutVisit'])) 
{
$last = $_COOKIE['AboutVisit']; }

In the first part of the code, we check to see if a cookie is set. If our cookie (named AboutVisit) is set, we retrieve it and assign it to the variable $last. It is important that we do this before we set the cookie, otherwise, we will overwrite the old date before we ever see it.

在代码的第一部分,我们检查是否设置了cookie。 如果设置了我们的cookie(名为AboutVisit),我们将其检索并将其分配给变量$ last。 在设置Cookie之前,请务必先执行此操作,否则,我们将在看到旧日期之前将其覆盖。


$year = 31536000 + time() ; 
//this adds one year to the current time, for the cookie expiration
setcookie(AboutVisit, time (), $year) ;

Next, we create a variable called $ year. This adds one year to the current date, by adding 31,536,000 seconds (60 seconds * 60 minutes * 24 hours * 365 days.) We use this as the new cookie's expiration date. We then set our new cookie to be the current time. We must be sure when we set a cookie that it is the first thing sent to the browser or it will not work. Any text, HTML, or even a page title will make it not work. These things should all follow the cookie.​

接下来,我们创建一个名为$ year的变量。 这将使当前日期增加一年,即增加31,536,000秒(60秒* 60分钟* 24小时* 365天)。我们将其用作新Cookie的到期日期。 然后,我们将新的cookie设置为当前时间。 我们必须确保在设置cookie时确保它是发送到浏览器的第一件事,否则它将不起作用。 任何文本,HTML甚至页面标题都将使其无法使用。 这些东西都应该放在cookie后面。

欢迎回来 ( Welcome Back )

This code first checks if $last is set. If you remember from the last step, $last is the time the visitor was last at the site. If they have visited before it then runs through two options. If the visitor has visited within the last day, it simply thanks them for visiting the site. If, however, the visitor visited over 1 day (86,400 seconds) ago, the message welcomes them back and reminds them of when they last visited.

此代码首先检查是否设置了$ last。 如果您还记得最后一步,则$ last是访问者在该站点上的停留时间。 如果他们在之前访问过,则通过两个选项进行。 如果访问者在最后一天访问过,则只感谢他们访问了该站点。 但是,如果访问者在1天(86,400秒)之前访问过,则该消息会欢迎他们返回并提醒他们上次访问的时间。

新用户 ( New Users )

If $last did not exist, then this code executes. It simply welcomes a first time user to the site. They now have a cookie set in their browser so they will not get this message again.

如果$ last不存在,则执行此代码。 它只是欢迎第一次使用该网站的用户。 现在,他们在浏览器中设置了Cookie,因此不会再收到此消息。

The top part of the script, that retrieves and sets the cookie, needs to be placed at the very top of a page to work. The rest of this script can run anywhere on your site that you want to welcome a user.

检索和设置cookie的脚本的顶部需要放置在页面的顶部才能工作。 该脚本的其余部分可以在您要欢迎用户的站点上的任何位置运行。

翻译自: https://www.thoughtco.com/you-last-visited-php-script-2693848

编写脚本电脑怎么编写界面

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值