Jump to content

Recommended Posts

I didnt really see where to post this so.......

Is there some way I can make a page or popup only appear for a visitor one time over like a year period of time

What Im looking to do is have a coupon for a free race entry a visitor can print off and use, but only have that option once per visitor.

Link to comment
https://forums.phpfreaks.com/topic/173822-one-time-popup-for-visitors/
Share on other sites

That might be easy or difficult to do, depending on your situation.

 

Solution #1

If your visitors are "members" of your site (i.e. do they have to log in first to get the coupon), you can easily track who received a coupon and who didn't within the last year. Let me know if this is the case.

 

Solution #2

You can track this using cookies. DRAWBACK - most people clear their cookies on a monthly basis so the cookie you added would soon disappear.

 

Solution #3

You can track visitors by their IP address using PHP, then block that IP from receiving another coupon until a year lapses. DRAWBACK - That visitor could get more coupons by simply visiting your site from another computer. Or if that visitor is using a public computer (at a library maybe) then you just blocked anyone else who uses that computer from receiving the coupon.

people with dynamic IP's will run into problems because they will be prompted to get another coupon. This also won't work with people who clear their cookies or have them disabled. Also if you use cookies people can easily alter the cookies.

 

Using a member system to decide will be the best way in my opinion.

create a table called `coupon` or what ever

fields:

id,user_id,coupon,date

 

check the table when the user goes to the coupon page to see if that session user already downloaded the coupon.

 

if not insert the record into the table and give them the coupon

well you can start here

 

<?php
//CONNECT TO THE DATABASE
$link=mysql_connect('localhost','USERNAME HERE','PASSWORD HERE');
mysql_select_db('DATABASE_NAME_HERE');

//QUERY THE TABLE TO SEE IF COUPON WAS ALREADY DOWNLOADED BY THIS USER
$sql='SELECT `id` FROM `coupon` WHERE `user_id`="'.$_COOKIE['user_id'].'" AND `coupon`="THE_COUPON_NAME" ';
$res=mysql_query($sql) or die($sql."<br>".mysql_error());
$downloaded=(mysql_num_rows($res)>0)?true:false;

if($download){
    //IF DOWNLOADED
    echo "YOU ALREADY DOWNLOADED THIS COUPON!";
}else{
    //IF NOT DOWNLOADED
    //INSERT INTO TABLE
    $sql='INSERT INTO `coupon` SET `user_id`="'.$_COOKIE['user_id'].'",`coupon`="THE_COUPON_NAME",`date`="'.time().'"';
    mysql_query($sql) or die($sql."<br>".mysql_error());
    //DISPLAY THE COUPON
    echo "your coupon here";

}


?>

 

someone who actually knows phpbb can chime in

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.