【发布时间】:2013-01-25 05:06:00
【问题描述】:
我只想让初次使用的用户“浏览”我的网站。我想用 JavaScript 做。我的意思是,如果用户从未看过我的网站并且这是他/她的第一次访问,他们将获得有关如何使用该网站的教程。如果他们再次访问或重新加载页面,他们不应该看到工具提示。这可以用 JavaScript Cookies 完成吗?我找到了一个 PHP 代码,但我现在想避免使用 PHP。
<?php
// Top of the page, before sending out ANY output to the page.
$user_is_first_timer = !isset( $_COOKIE["FirstTimer"] );
// Set the cookie so that the message doesn't show again
setcookie( "FirstTimer", 1, strtotime( '+1 year' ) );
?>
<H1>hi!</h1><br>
<!-- Put this anywhere on your page. -->
<?php if( $user_is_first_timer ): ?>
Hello there! you're a first time user!.
<?php endif; ?>
如果用JS做不到,可以用.htaccess做吗?我还发现了这个:
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^(www\.)?(https?://)?(?!example\.com) [NC]
Rewriterule ^(.*)$ http://example.com/welcome.html [r=307,NC]
【问题讨论】:
-
如果 cookie 不存在,请执行您的工具提示内容。否则,不要。
-
我对 Cookie 没有任何经验,我在网上找不到与我的主题相关的任何内容。
标签: javascript html .htaccess cookies