Wow. Is this possible in PHP?

Discussion in 'PHP' started by jacobbannier, Sep 26, 2006.

  1. #1
    I have popups which i want to show to one IP address every hour. How do i do this with a simple PHP, or can you redirect me to one.
    Thanks,
    Jacob
     
    jacobbannier, Sep 26, 2006 IP
  2. eli03

    eli03 Well-Known Member

    Messages:
    2,887
    Likes Received:
    98
    Best Answers:
    0
    Trophy Points:
    175
    #2
    you can do simple if condition: e.g

    <?php
    $ip="1.1.1.1";

    if($ip != "1.1.1.1") {
    // do nothing

    } else {
    //pop script here
    }

    <?
     
    eli03, Sep 26, 2006 IP
  3. disgust

    disgust Guest

    Messages:
    2,417
    Likes Received:
    133
    Best Answers:
    0
    Trophy Points:
    0
    #3
    eli03 is off to the right start but it's not exactly the entire code you'd need. you have a few options.

    1) store the ip's in a flat file with the last time visited associated with it
    2) do the same but with mysql.
    3) use cookies.

    the third is usually ideal.
     
    disgust, Sep 26, 2006 IP
    ahkip likes this.
  4. runnerunner

    runnerunner Active Member

    Messages:
    1,027
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    90
    #4
    <?
    $cookie=$_COOKIE['time'];
    if ($cookie!='on')
    {
    setcookie('time', 'on', time()+3600);
    /// insert code for ad here
    }
    ?>
    PHP:
    not a great coder, but i think that's what you'd want.
     
    runnerunner, Sep 26, 2006 IP
    ahkip likes this.
  5. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #5
    Edit: Almost same code as above. Was not there when I first looked at the thread.
    ----
    Try this:

    <?php
    if($_COOKIE['pop'] != "333")
    {
    setcookie('pop', '333', time()+3600);
    // sets a cookie for 1 hour.
    // Pop up code here.
    }
    ?>

    On the first visit the cookie will not be found, Popup comes up. Plus cookie is set.
    For the next 1 hour, the cookie is found, No popup.
    After 1 hour cookie expires, popup comes up again. Plus new cookie set.
    Hope that helps.
    Bye :)
     
    JEET, Sep 26, 2006 IP
  6. jacobbannier

    jacobbannier Active Member

    Messages:
    1,155
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    90
    #6
    Wow, that was the fastest response :eek: Its good ill give it a go :) Thanks guys. P.S check back to see if it worked :p
     
    jacobbannier, Sep 26, 2006 IP
  7. jacobbannier

    jacobbannier Active Member

    Messages:
    1,155
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    90
    #7
    I used this code:
    <?php
    if($_COOKIE['pop'] != "333")
    {
    setcookie('pop', '333', time()+3600);
    // sets a cookie for 1 hour.
    // Pop up code here.
    <script src="http://www.adversal.com/cg.jsp"></script>
    <script src="http://www.adversal.com/publisherJS.jsp"></script>
    <script type="text/javascript" language="javascript">
    initAdversal("8708bb9d80806013c99bb1910fb0a7cc", true);
    </script>
    }
    ?>
    Is that right, becase when i try to use it it says
    "Parse error: syntax error, unexpected '<' in /home/admin/public_html/poxy-0.4/url_form.inc on line 43"
    Am i coding it wrong?
     
    jacobbannier, Sep 26, 2006 IP
  8. VONRAT

    VONRAT Banned

    Messages:
    181
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    ahem ... is that exactly how the code looked like? B'coz if it is then try doing it something like
    
    <?php
    if($_COOKIE['pop'] != "333")
    {
    setcookie('pop', '333', time()+3600);
    // sets a cookie for 1 hour.
    // Pop up code here.
    echo '
    <script src="http://www.adversal.com/cg.jsp"></script>
    <script src="http://www.adversal.com/publisherJS.jsp"></script>
    <script type="text/javascript" language="javascript">
    initAdversal("8708bb9d80806013c99bb1910fb0a7cc", true);
    </script>';
    }
    ?>
    
    PHP:
    :)
     
    VONRAT, Sep 26, 2006 IP
  9. jacobbannier

    jacobbannier Active Member

    Messages:
    1,155
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    90
    #9
    Thanks, i repped you both. If i wanted to apply this time for one IP but not another, is that a way to do that? Like combine a IP chooser kind of.
     
    jacobbannier, Sep 26, 2006 IP
  10. disgust

    disgust Guest

    Messages:
    2,417
    Likes Received:
    133
    Best Answers:
    0
    Trophy Points:
    0
    #10
    list ip's you don't want in an array. http://us3.php.net/manual/en/ref.array.php

    define the ips you don't want to trigger it, then use the code below

    
    <?
    $nopop[0] = "xx.xx.xx.xx";
    $nopop[1] = "xx.xx.xx.xx";
    
    if (strpos($_SERVER['REMOTE_ADDR'], $nopop) === 0))
    {
    // the cookie code here
    }
    ?>
    
    PHP:
     
    disgust, Sep 26, 2006 IP
  11. codeber

    codeber Peon

    Messages:
    578
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #11
    settings cookies isnt always effective.

    if it were me, I'd store it in a session. (its easiest if you have already one running)
     
    codeber, Sep 26, 2006 IP
  12. disgust

    disgust Guest

    Messages:
    2,417
    Likes Received:
    133
    Best Answers:
    0
    Trophy Points:
    0
    #12
    most users that have cookies turned off are probably the sort of user that has some fairly advanced adblocking software installed too, so it seems kind of moot to me.

    and it's not like sessions aren't without downfalls either.
     
    disgust, Sep 26, 2006 IP
  13. jacobbannier

    jacobbannier Active Member

    Messages:
    1,155
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    90
    #13
    Na.. cookies are fine, it doesn't have to be perfect.
     
    jacobbannier, Sep 26, 2006 IP
  14. cancer10

    cancer10 Guest

    Messages:
    364
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Cookies are okay but what if the user has their cookie blocked in their browser?
     
    cancer10, Sep 27, 2006 IP
  15. jacobbannier

    jacobbannier Active Member

    Messages:
    1,155
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    90
    #15
    And then they a get a popup every time. It isn't that bad after all most proxy sites have a popup every load. I get enough traffic with a popup each load so it doesn't matter. Also i repped disgust :)
     
    jacobbannier, Sep 27, 2006 IP