1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[Help]Php code to show iframe every 25-30 visitors?

Discussion in 'PHP & Perl' started by sk8tavou, Oct 9, 2012.

  1. sk8tavou

    sk8tavou Senior Member

    Joined:
    Aug 28, 2011
    Messages:
    1,130
    Likes Received:
    1,333
    Hello guys!
    I want to iframe a link on my website but i want it to be visible every 25-30 visitors!
    So something like to choose a random number from 1-25 and everytime the number is 9 to show the iframe on the page!

    As i know nothing about php i have no idea how to do it!
    Any help is appreciated [​IMG]
    Also my iframe code seems not to work so good so if anyone can provide a new one i will appreciate it a lot [​IMG]

    Thanks in advance!

    Ps:i also posted this in jr vip forum but now i think its better to have more people to see it :)
     
  2. istart

    istart Junior Member

    Joined:
    Oct 10, 2011
    Messages:
    116
    Likes Received:
    26
    Occupation:
    Web developer - apps and db.
    Location:
    Canada
    A random number won't work for this. You'll have to store a running count in a text file or DB though. Pm me the details if u wasn't me to help!
     
    • Thanks Thanks x 1
  3. Xp3r7

    Xp3r7 Regular Member

    Joined:
    Sep 9, 2011
    Messages:
    286
    Likes Received:
    386
    Occupation:
    Freelancer
    Location:
    In the middle of nowhere
    Yeah. You need to keep trackof your visitors number and then do something like this:

    PS: You can store the IPs of the users and then count them. So you'll make sure that your iframe will show only for 30 unique visitors.
     
    • Thanks Thanks x 1
    Last edited: Oct 9, 2012
  4. sk8tavou

    sk8tavou Senior Member

    Joined:
    Aug 28, 2011
    Messages:
    1,130
    Likes Received:
    1,333
    Thanks a lot both for the replies! But why a random number wont work?
    if ($randomnumber == 9) {
    echo 'Your iframe code';
    }

    again i dont know php so maybe my question seems silly :p
     
  5. Xp3r7

    Xp3r7 Regular Member

    Joined:
    Sep 9, 2011
    Messages:
    286
    Likes Received:
    386
    Occupation:
    Freelancer
    Location:
    In the middle of nowhere
    Because if $randomnumber is generated randomly(rand function) you don't know when your random generated number will be equal to 9.

    PS: Added you on Skype.
     
    • Thanks Thanks x 1
  6. spruitje

    spruitje Junior Member

    Joined:
    Oct 8, 2011
    Messages:
    138
    Likes Received:
    64
    Location:
    on top
    Just started with php but I think something like this should work:


    $randomNum = rand(1,30);
    if ($randomNum == 9) {

    iframe

    }
     
  7. spruitje

    spruitje Junior Member

    Joined:
    Oct 8, 2011
    Messages:
    138
    Likes Received:
    64
    Location:
    on top
    That's the whole point right? For a small amount of visitors the iframe could be active for more then 1 in 30, but as the visitor count increases it averages out to 1/30.
     
    • Thanks Thanks x 1
  8. istart

    istart Junior Member

    Joined:
    Oct 10, 2011
    Messages:
    116
    Likes Received:
    26
    Occupation:
    Web developer - apps and db.
    Location:
    Canada
    If you generate a random number every time some one his that page, it may never pick 9. Or it might pick 9, three times in a row.

    That won't get your I frame showing up anywhere near once every 30 visits.
     
  9. sk8tavou

    sk8tavou Senior Member

    Joined:
    Aug 28, 2011
    Messages:
    1,130
    Likes Received:
    1,333
    Thanks mate for your help! I worked with Xp3r7 and he made the code for me :)
     
  10. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,143
    Did you really have to crosspost the same question in 2 different places?
     
  11. chattr777

    chattr777 Newbie

    Joined:
    Oct 15, 2012
    Messages:
    3
    Likes Received:
    0
    Here's the code: pastebin / AjwCy4Th (BHW filters don't allow me to post URLs)
    Embed this code into your page.
    You're welcome.