protecting a page using captcha

Discussion in 'PHP' started by Napoleon, Nov 6, 2008.

  1. #1
    Hello, I want to protect a few pages on my site using captcha. Once the user identifies himself using a captcha, he need not do it again for the other pages, until he clears cookies. Is it possible to do it? Almost all captcha examples are for web forms.
     
    Napoleon, Nov 6, 2008 IP
  2. Lordo

    Lordo Well-Known Member

    Messages:
    2,082
    Likes Received:
    58
    Best Answers:
    0
    Trophy Points:
    190
    #2
    Sure! You will have captcha on all forms with an if before it. Check if a cookie exists or not. If so, then do not show captcha and do not check for its value on the result page. What is confusing you? Or do you wonder if it is possible?
     
    Lordo, Nov 6, 2008 IP
    Napoleon likes this.
  3. money4leads

    money4leads Well-Known Member

    Messages:
    117
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #3
    you need to create session when user identify him self, then

    
    if(isset($_SESSION["user"]))
      {
       //don't show captcha 
    }
    else {
    
    //show captcha
    
    }
    
    
    PHP:
     
    money4leads, Nov 6, 2008 IP
    Napoleon likes this.
  4. Napoleon

    Napoleon Peon

    Messages:
    732
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I tried using cookies, but I'm getting this error
    Warning: Cannot modify header information - headers already sent by (output started at /home/xxxxxx/public_html/verify.php:8) in /home/xxxxxx/public_html/verify.php on line 28
    Code (markup):
     
    Napoleon, Nov 6, 2008 IP
  5. Lordo

    Lordo Well-Known Member

    Messages:
    2,082
    Likes Received:
    58
    Best Answers:
    0
    Trophy Points:
    190
    #5
    What is at that line?
     
    Lordo, Nov 6, 2008 IP
  6. Napoleon

    Napoleon Peon

    Messages:
    732
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Line 28 is setcookie("real", "Real User", time()+36000);
    Line 8 is echo(<head><body><form action=\"\" method=\"post\">);
     
    Napoleon, Nov 6, 2008 IP
  7. Napoleon

    Napoleon Peon

    Messages:
    732
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I used ob_start(); at the start of my script and its not giving me the error anymore
     
    Napoleon, Nov 6, 2008 IP
  8. keyaa

    keyaa Peon

    Messages:
    137
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Good fix, although you should try to always send all your headers before sending anything else (e.g. xhtml).
    Another (more ugly) fix would have been to set the Cookie via JavaScript.
     
    keyaa, Nov 6, 2008 IP
    Napoleon likes this.
  9. Napoleon

    Napoleon Peon

    Messages:
    732
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Well, I will only use the captcha on leeching bots, so I'm not much worried about standards:D
     
    Napoleon, Nov 6, 2008 IP
  10. xrvel

    xrvel Notable Member

    Messages:
    918
    Likes Received:
    30
    Best Answers:
    2
    Trophy Points:
    225
    #10
    xrvel, Nov 7, 2008 IP
    Napoleon likes this.