SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict sedna's Avatar
    Join Date
    Jan 2006
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    captcha within form?

    Hey all I search the forums how to make a small captcha thanks SpikeZ however I am having problems intergrating it into my form? I have tried but I seem to be having errors and I have tried google but the way people explain it is far to hard for me to understand me newbie here lol.

    My Login.html Code
    HTML Code:
    <html>
    
    <head>
    	<title>Login</title>
    </head>
    
    <body>
    
    <h1>Login Here</h1>
    <form action="members.php" method="post"/>
        <input type="text" name="username">
        <input type="text" name="password">
        <tr>
    <td width="150">Enter Number</td>
    <td><input name="txtNumber" type="text" id="txtNumber" value="">
    <img src="imagecap.php"></td>
    </tr>
        <input type="submit" name="submit" value="Login">
        <input type="hidden" name="loginform" value="1">
    </form>
    </body>
    </html>
    My members PHP Code

    PHP Code:
    <?php

    /**
     * @author Cobra Internet
     * @copyright 2008
     */

    $username ="admin";
    $password "max";

    if(isset(
    $_POST['loginform'])){
        
        if(
    $_POST['username']== "admin") && ($_POST['password'] == "max") && ($_POST['txtNumber']) ? strtolower($_POST[                'txtNumber']) : "";
        if (
    $txtNumber == $_SESSION['captcha']) {
            echo 
    'Welcome to the members section';
            
        } else {
            
            echo 
    'you are not logged in';
        }

    }
    ?>
    I dont think you will need the captcha code as all that does it makes the image etc... and creates the session called captcha.
    Joe

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,510
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    What are the errors you're getting?

  3. #3
    SitePoint Addict sedna's Avatar
    Join Date
    Jan 2006
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No errors at all, according to php my syntax is correct lol but it's not if you see what I mean

  4. #4
    SitePoint Addict sedna's Avatar
    Join Date
    Jan 2006
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php

    /**
     * @author Cobra Internet
     * @copyright 2008
     */

    $username ="admin";
    $password "max";

    if(isset(
    $_POST['loginform'])){
        
        if((
    $_POST['username']== "admin") && ($_POST['password'] == "max") && ($_POST['txtNumber'] == $_SESSION['captcha']))
        {
         
            echo 
    'Welcome to the members section';
            
        } else {
            
            echo 
    'you are not logged in';
        }


    }
    ?>
    I have updated my code, the problem I am getting now is if I dont enter anything in the username and password fields it will not let me login which is what I wanted however if they enter the correct username and password but dont enter that captcha the system still lets them login? thats the problem that I am having how do I intergrate the captcha with my form so that it compares what the user has entred to that held within the captach session. if there is a match the user can login

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,510
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Do you have session_start() at the beginning of your members php code?
    And what happens if you enter the right or a wrong captcha?

  6. #6
    SitePoint Addict sedna's Avatar
    Join Date
    Jan 2006
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks quido2004 for your help Like you said it was becuase I did not have session_start() at the beginning of my members page.

    Dam php is soooo hard compared to visual basic lol but I am going to stick it out!!


Bookmarks

Posting Permissions

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