php – 第一次访客Cookie

对于我的网站,我想在页面中间为首次访问者创建一个链接,使用PHP说“首次点击此处”.

解决方法:

理论上你可以用cookie来做,但除了要求他们注册一个帐户并在他们第一次登录时向他们显示消息时,没有保证能够检测到“第一次访问者”.

原因是cookie可能会从浏览器中清除,人们可能会更改计算机/浏览器,cookie最终会过期,并且取决于您的目标是什么,最终会让现有用户感到厌烦,假设他们是新用户.

无论如何,够了.您的代码可能如下所示:

<?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; ?>

干杯!

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...