Dynadot โ€” .com Transfer

Having trouble With Verification Code

SpaceshipSpaceship
Watch
Impact
0
Hi!

I've been trying to set up a Human Verification system for my website forms. I cannot stand CAPTCHA and refuse to use that. Thankfully many people agree with me on that end :D

However, I'm trying to use the code from this thread:
Simple Human Verification Code

Yet . . . I am admittedly a PHP "noob" with this. I started to learn PHP a good while back, yet time constraints hindered that and I learned next to nothing it seems.

I was wondering if I could get some possible help on this. My forms are HTML, and they call a php file to email the form to me. That's just about it. I created a php file for the questions/answers in case form (first block of code), copy/pasted the code into it (the file contains nothing but the code). However, I think my problem is that I don't quite understand where and how to place the second block of code. It first showed up as regular text in my form. Then I put it between the PHP tags . . . and my page disappeared :D

The field has been added to my form (third code block), and shows fine except no questions show up, obviously due to not being called properly somewhere? Then the fourth block of code was placed in the file where I e-mail the form to myself.

I would ask this question in that very thread, but I noticed that place is mostly for discussion and not tutorial, which is what I believe my problem is: needing to learn what in the world to actually do with this code! So I hope I'm not posting this in the wrong place. If so, I apologize!

I was wondering, and hoping, that I could get some help with this problem? I've put off such a feature of my forms for too long and am getting tired of bots using my forms and sending me trash nearly every day it seems. So any help with this would be GREATLY appreciated, as soon as I can so I can get rid of the bot troubles.

Thank you in advance!
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
please show your html/php file, I hate to read text, I love code :)
 
0
•••
The first portion of code should be saved into a file called "whatever.php". The original post is missing the PHP open/close tags, so you'll need to add them round the code:

PHP:
<?php
// code goes here
?>

The second block of code should go at the top of the page which shows the form. It should also be a PHP page, and you'll need to put PHP tags round it. You need to change the "path/to/whatever.php" part to match where you put whatever.php. If you put whatever.php in the same directory as the mail form, then add the following to the top of the mail form file:

PHP:
<?php
require('whatever.php');
$_SESSION['antibotcode'] = md5(strtolower($bota));
session_write_close();
?>

In the middle of your mail form add the third block. If your mail form is not within PHP tags, then use:

PHP:
<p style="margin-top:0px;padding-top:0;"><span style="color:red;">* Human verification: </span><strong>' . <?php echo $botq; ?> . '</strong><br style="height:35px;" /><input type="text" name="b" /></p>

The 4th block of code goes in your PHP mail script. I don't think it is quite complete, since it displays messages, but carries on. You might want to use something like this instead:

PHP:
    if (!empty($_POST['b'])) {
        $b = md5(strtolower($_POST['b']));
    } else {
        echo 'Go back and fill out all fields! Pretty please?';
        exit;
    }
    if (!empty($_SESSION['antibotcode'])) {
        if ( $b != $_SESSION['antibotcode'] ) {
            unset($_SESSION['antibotcode']);
            echo 'Code typed incorrectly. Go back.';
            exit;
        }
    } else {
        echo 'Hmmm, how did you get here without the proper session being set?';
        exit;
    }
    unset($_SESSION['antibotcode']);
                // all is good, continue parsing form!

put this just before the "mail" function call.
 
0
•••
Thank you both for the help! Sorry it's taken me so long to get back with you and this topic :(

Thanks for the suggestions, qbert, it did help a lot! Although . . . the page with the form itself:

It's actually an HTML page. I have about . . . 30 or so pages with forms on them that I'm needing to add this verification system to it, and they're all in HTML. So I can't really change them to php. Is there a way to get around and use it in an HTML File?

Currently I have this code in the file, and apparently it's broken as the page shows blank when I add the php code from the second block. I suppose I'm misplacing it, or it's because it's within an HTML file?:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Contact Us</title>

<?php 
session_start()
 require('questions.php');
    $_SESSION['antibotcode'] = md5(strtolower($bota));
    session_write_close(); 
?>


<link rel="stylesheet" href="style.css" type="text/css">
</head>

<body>


		
			<div class="sidebar">
			<?php include 'strip.txt'; ?>
			</div> <!--End of Sidebar Div-->
                               
<div class="main">
			
			<div class="header">
			<img src="images/wfc&2tim2_15.gif" alt="Workmen for Christ" width="394" height="45"><p>
			<br>
			<br>
			
			<h3></h3><p>
			<br>
			<br>
			</div> <!--End header div-->

<div class="maintext">
			<h1>Contact Us</h1><br>

<div class="maintext2">
			
			<p>If you're reporting a problem that occurred on the website, please list the Web Address or page on which the problem occurred.</p>


<form method="post" action="contact.php">
<input type="hidden" value="Comment (or Problem)" name="Subject">
<span class="topicsub" style="font-weight:bold;">Comment (Or detailed explanation of a problem you are experiencing):</span><br>
<textarea wrap="virtual" name="Problem" rows=10 cols=70></textarea>
<br>
<br>

<span class="topicsub" style="font-weight:bold;">Web Address or Page you experience a problem:</span><br>
<input type="text" name="URL" size="60">
<br>
<br>

<span class="topicsub" style="font-weight:bold;">E-mail address I can reach you when the problem is solved</span><br>
<input type="text" name="Email" size="30">
<br>
<br>

<span class="topicsub" style=" color:red;">* Human verification: </span><strong><?php echo $botq; ?></strong><br>
<input type="text" name="b" />
<br><br>

<h2>Thanks!</h2>
<span class="center"><input type=submit value="Submit">ย ย 
<input type=reset value="Clear">
</span>
</form>

</div> <!--End maintext2 div-->
</div> <!--End maintext div-->
</div> <!--End main div-->
			

</body>
</html>
I apologize, I'm sure the code seems sloppy or something. I really need to get back into coding, since I made the site 5 years ago, and that's exactly what I'm hoping to do---starting with this verification system :D

I appreciate everyone's continued help with this. Thanks again!
 
0
•••
If the page goes blank, then it's probable that the page is already being treated as a PHP script, not an HTML file. There may be a PHP error log file (perhaps called error_log in the same directory). Ask you host where PHP errors get logged to.

There is a missing ";" in the session_start() line. It should be:

PHP:
<?php 
    session_start();
    require('questions.php');
    $_SESSION['antibotcode'] = md5(strtolower($bota));
    session_write_close(); 
?>
 
0
•••
Send me the file and I will fix it for you brother. info at driaconsulting.com

just make sure to give me a rep point when done:)
 
0
•••
Appraise.net
Spaceship
Domain Recover
CatchDoms
DomainEasy โ€” Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back