For my site, I want to create a link in the middle of the page for first time visitors that says something like "First time, click here" using PHP.
You could in theory do it with cookies, but there's no guaranteed way to detect "first time visitors" other than asking them to register for an account and show them the message the first time they log in.
The reason is that cookies may get cleaned from the browser, people may change computers / browsers, cookies will eventually expire and depending on what your goal is you may end up annoying existing users assuming they're new.
Anyway, enough of that. Your code could look something like this:
<?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; ?>
Cheers!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With