Jump to content

Recommended Posts

hi

i was wondering if anyone can give me a hand adding this captcha script? i have tried everything i can think of with no luck at all. I think my problem has to do with the session where i already have one started  but i could be wrong, any help would be great thanks.

 

My code:

<?php
include("db.php");
$error_message="";
$email_to    = mysql_real_escape_string(strip_tags($_POST['email_to']));
$today = date("M d, Y h:i A");
$ip = $_SERVER['REMOTE_ADDR'];
if (isset($_POST['submit'])){
    if($_SERVER['REQUEST_METHOD'] == 'POST')
    {
        if(!isset($_SESSION['csrf']) || $_SESSION['csrf'] !== $_POST['csrf'])
        $sql = "SELECT username FROM users
        WHERE mailaddress = '{$email_to}'";
        $result=mysql_query($sql, $conn)
        or die('Error in query:<br>'. $sql .'<br>'.mysql_error($conn).'<br>Time of Error: '.date("l F j, Y, G:i:s T"));
        $count=mysql_num_rows($result);
        if($count==1){
            $rows=mysql_fetch_array($result);
            $username=htmlentities($rows['username']);
            $to=$email_to;
            $subject="mysite Username reminder.";
            $header="from: noreply@mysite.com";
            $messages= "Hey $username, \r\n";
            $messages.=" \r\n";
            $messages.="You recently request your mysite username on $today \r\n";
            $messages.=" \r\n";
            $messages.="Your username is: $username \r\n";
            $messages.=" \r\n";
            $messages.="You can sign in at: https://www.mysite.com \r\n";
            $messages.=" \r\n";
            $messages.="Your username was requested from the following ip address: $ip \r\n";
            $messages.=" \r\n";
            $messages.="Thanks, \r\n";
            $messages.="From mysite.com \r\n";
            $sentmail = mail($to,$subject,$messages,$header);
        }
        else {
            $error_message = 'Sorry email address not found.';
        }
        if($sentmail){
            $error_message = 'Your username has been sent to your email address.';
        }
        else {
            $error_message = 'username was not sent please try again.';
        }
    }
}
$key = sha1(microtime());
$_SESSION['csrf'] = $key;
?>

 

Captcha code trying to add:

<?php
session_start();
if (md5($_POST['csrf']) == $_SESSION['csrf']){
    $error_message = 'Captcha good.';
    } else {
    $error_message = 'Captcha wrong.';
}
?>

Link to comment
https://forums.phpfreaks.com/topic/265707-problem-adding-captcha-to-script/
Share on other sites

hi bleured27

thanks for the reply, i have search google and came up with a lot of scripts and have a captcha script. The code i posted (my captcha script) is the part im having problems adding to my script, i been watching tuts for 2 days and did learn a lot but still am having a problem with adding that bit of code.

are you dutch because i Know dutch help for you

i translated it

it will be a math question example 1+1 = [      input box        ]

 

 

<?php 
session_start(); 
require_once 'Numeral.php'; 
$numcap = new Text_CAPTCHA_Numeral;

//your stuff
if (isset($_POST['captcha']) && isset($_SESSION['answer'])) { if ($_POST['captcha'] == $_SESSION['answer']) { } else { $vervuild = TRUE; $melding .= "plz try captcha again "; }

more tomorrow i go sleep

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.