Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2003
    Posts
    959

    How to set cookies for IP?

    hello,

    Recently we are being mucked around by a same IP, finally blocked it but then I need to get a cookies setup in my form.

    Here is what my form looks like

    .shtml --- actual form
    contact.php ---- check error and send email

    If i was to add a cookie so it will check the IP whether they have tried to submit before or within 24 hours, it will redirect to another page.

    What should I add to it?

    Thanks

  2. #2
    Join Date
    Jan 2003
    Location
    Perth, WA, Australia
    Posts
    1,276
    Before your validations, do:
    PHP Code:
    if (isset($_COOKIE['email_lock']))
        echo 
    'You already sent an email!';

    else {
        
    // The code to validate and send the email

    When the email has been "successfully sent," do:
    PHP Code:
    setcookie('email_lock',1,time() + 86400,'/'); 
    Note that cookies can only be sent before any output has been sent to the browser.

    Hope this helps.
    nu-metal.org :: coming soon

  3. #3
    Join Date
    Feb 2004
    Posts
    772
    Hi,

    You can set cookie in your PHP page using the setcookie() function, which looks like this:

    int setcookie(string name, string value,
    int expire, string path, string domain,
    int secure);

    For more details please refer this URL:

    http://perl.about.com/library/weekly/aa051600b.htm

    Regards,

    Bright

  4. #4
    Join Date
    Aug 2002
    Location
    Canada
    Posts
    665
    Remember that IPs are unreliable. Switching proxies and farms will report switching IPs (like AOL clients) so even the most complex IP reporting function will not be entirely accurate.

    The better tactic is to store a cookie in the client browser and check for that cookie instead, or at least in addition.

    Cheers
    A
    circlical - hosting software development
    forums * blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •