PHP script to block an Ip address for a determined amount of time???

Discussion in 'PHP' started by TM101Radio, Mar 23, 2011.

  1. #1
    I run an internet radio station and one of the features I have been working on is adding text requests to my station website..

    SO far i was able to make one with a hacked up "Contact Form" script combined with "SMS Gateways" and it works great so far....only issue I have is I want to block an IP address from making multiple request in a like say a 2 hour period.

    Basically I want to allow a listener to only make 1 song request every 2 hours via the text request form...

    the way the script i have works now is it takes a simple form and when a listener hits the submit button it send me a text message via the sms gateway..the form was initially set up as a "Contact Us" form to send the station an email directly from our website..so with a little modding I just swapped the recieving email address in the form with my sms gateway email address...and the result is sent to my cell phone..

    I been googling for 2 days to find something to help with this and all i find is code to permanently block an IP address that I added to a .txt file..This is not what i want to do..

    ANY HELP WITH THIS WOULD BE GREATLY APPRECIATED...THANKS
     
    TM101Radio, Mar 23, 2011 IP
  2. joy1986joy

    joy1986joy Member

    Messages:
    189
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #2
    Blocking by ip is a good idea. But you can also do it by the phone number or the user account. That will be easy to do also.
     
    joy1986joy, Mar 24, 2011 IP
  3. TM101Radio

    TM101Radio Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I dont want to block them permanently just for a set amount of time..

    and the form is for the TEXT request is web based so the listener requesting a song doesn't need to send us a txt from there phone...we have listeners in 150+ countries so the request form being web based can allow any listener in any country to send the txt request..thus we wont recieve any TEXTS from a cell phone...so blocking numbers is not an option

    also currently I dont have a membership based website..just a really quick and easy way for people to tune in on my site so blocking by username is not an option neither...

    you can see a demo of my current script here... (i can't post links yet so bear with me)

    tm101radio dot com/indexwithvideos dot html

    just click the link that says "TEXT US A SONG REQUEST" and after you submit our station phone will recieve the txt..

    Im still for like 4 days now been searching for a way to just temporarily block an IP address for making multiple request within a set period of time..
     
    TM101Radio, Mar 24, 2011 IP
  4. joy1986joy

    joy1986joy Member

    Messages:
    189
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #4
    Hello
    I don't have the code but I can suggest you one thing. I have seen in some forums there is a blocking system in IP for a time limit like 5 min between two posts. You can download any php based free forum and try search for the procedure. I know it is tough but you can try it as your last option.
     
    joy1986joy, Mar 24, 2011 IP
  5. TM101Radio

    TM101Radio Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks I will look into that..but i was wondering also if maybe a session cookie can accomplish this as well.???
     
    TM101Radio, Mar 24, 2011 IP
  6. joy1986joy

    joy1986joy Member

    Messages:
    189
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #6
    Yes it can but with IP it is little difficult. Generally people block IP by .htaccess but in some case it is different. try to google it. Best of luck.
     
    joy1986joy, Mar 24, 2011 IP
  7. sojic

    sojic Active Member

    Messages:
    133
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    90
    #7
    It is not so simply.

    If I were you, I will do it with firewall (iptables). It is relative complicated script which "monitoring" the network, execute iptables commands, open/closing ports, so the client will be able to surf the site, but streaming port is closed for his IP.
     
    sojic, Mar 25, 2011 IP
  8. TM101Radio

    TM101Radio Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8

    I dont want to block the streaming port..Im not trying to block them from listening to the music....I want to block them from submitting a form multiple times!!!!
     
    TM101Radio, Mar 25, 2011 IP
  9. sojic

    sojic Active Member

    Messages:
    133
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    90
    #9
    Sorry, I did not read it carefully.
     
    sojic, Mar 26, 2011 IP
  10. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #10
    you have to save their ip into db (mysql) with time_end column and then you have to check it when submitting form

    <?php
    $blocked_ip = mysql_query("SELECT count(ip) as blocked FROM blocked WHERE ip = '".$_SERVER['REMOTE_ADDR'].";");
    if (mysql_fetch_assoc($blocked_ip))
    {
    if ($blocked_ip['blocked'])
    {die(you_already_submitted_it);}
    else{///pass}
    }
     
    G3n3s!s, Mar 26, 2011 IP
  11. TM101Radio

    TM101Radio Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Can you walk me thru setting that up???? Do I just add that to my current script? and How do I set up the database to work with that? Thank you for your reply it looks very promising..
     
    TM101Radio, Mar 26, 2011 IP
  12. seopriest

    seopriest Member

    Messages:
    347
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    28
    #12
    im also in that thing .... any help please
     
    seopriest, Jun 19, 2011 IP
  13. bhavatmaj

    bhavatmaj Well-Known Member

    Messages:
    319
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #13
    add time stamp on your form when submited by the ip.
    and the compare the time stamp with 2 hrs and same ip. or form will not show up
     
    bhavatmaj, Jun 21, 2011 IP
  14. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #14
    bhavatmaj
    do you think somebody look on this thread anymore ?
     
    G3n3s!s, Jun 22, 2011 IP