Jump to content

Help please. For project.


pnssassin

Recommended Posts

Hello,

 

I used code to make a very basic forum for a project but now people are posting random crap so I need to add recaptcha. The forum worked fine before but now I cant get recaptcha to work and i just get the entered incorrect error.

 

create_topic.php:

 

 
<body bgcolor="yellow">
<table cellspacing="1" cellpadding="0" width="400" align="center" bgcolor="#cccccc" border="1">
<tbody>

<tr>


<form id="form1" name="form1" method="post" action="add_topic.php">

   <?php
     require_once('recaptchalib.php');
     $publickey = ""; // you got this from the signup page
     echo recaptcha_get_html($publickey);
   ?>
  


<td>
<table cellspacing="1" cellpadding="3" width="100%" bgcolor="#ffffff" border="1">
<tbody>
<tr>
<td bgcolor="#e6e6e6" colspan="3"><strong>
<center>Create New Topic</center></strong></td></tr>
<tr>
<td width="14%"><strong>Topic</strong></td>
<td width="2%">:</td>
<td width="84%"><input id="topic" size="50" name="topic" /></td></tr>
<tr>
<td valign="top"><strong>Detail</strong></td>
<td valign="top">:</td>
<td><textarea id="detail" name="detail" rows="3" cols="50"></textarea></td></tr>
<tr>
<td><strong>Name</strong><br />
(enter "Anonymous" if you wish)</td>
<td>:</td>
<td><input id="name" size="50" name="name" /></td></tr>
<tr>
<td><strong>Email</strong> (unnecessary)</td>
<td>:</td>
<td><input id="email" size="50" name="email" /></td></tr>
<tr>
<td> </td>
<td> </td>


<td><input type="submit" value="Submit" name="Submit" /> <input type="reset" value="Reset" name="Submit2" /></td></tr></tbody></table></td></form></tr></tbody></table><br /><hr />
<font color="green"><center><a href="http://www.skoolforum.com/main_forum.php" >Back to Forum</a> <a href="http://www.skoolforum.com" >Back to Main Page</a></center></font>
</body>

 

add_topic.php

 <body bgcolor="ffff00">
<?php
$host="";
$username="";
$password="";
$db_name="";
$tbl_name="";



mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$topic=$_POST['topic'];
$detail=$_POST['detail'];
$name=$_POST['name'];
$email=$_POST['email'];

$datetime=date("d/m/y h:i:s");

require_once('recaptchalib.php');
$privatekey = "";
$resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);


if (!$resp->is_valid) {
   // What happens when the CAPTCHA was entered incorrectly
   die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
        "(reCAPTCHA said: " . $resp->error . ")");
} 

$sql="INSERT INTO $tbl_name(topic, detail, name, email, datetime)VALUES('$topic', '$detail', '$name', '$email', '$datetime')";
$result=mysql_query($sql);
echo "<CENTER><H1><STRONG>Successful post!</STRONG></H1></CENTER><BR><HR />"; 
echo "<CENTER><FONT COLOR='GREEN'><a href='http://www.skoolforum.com/main_forum.php' >View your topic</a> <a href='http://www.skoolforum.com' >Back to Main Page</a></FONT></CENTER>";



mysql_close(); 
?>
</body> 

 

Please tell me what I am doing wrong? the forum works before i added the recaptcha and i cant just revert it i need to have the recaptcha on there. Help me please!

 

Link to comment
Share on other sites

I can't see anything obvious wrong with what you've done. What happens now when you try to post? Do you get any errors? Does the script stop?

 

Please also look at mysql_real_escape_string() (http://uk2.php.net/mysql_real_escape_string) for escaping the data before you insert it into your database.

 

EDIT: Apologies, I've just seen that you did mention that the script replies with invalid response. Are your public and private keys definitely correct? I wouldn't be posting them on a public form either. Is probably wise to delete them from your original post.

 

EDIT2: I've just checked http://wiki.recaptcha.net/index.php/FAQ#It.27s_not_working.21_Help.21 and it appears that the key is domain specific. Are you sure that you're sending the correct domain? echoing $_SERVER["REMOTE_ADDR"] should confirm.

Link to comment
Share on other sites

In that case, maybe try some debugging in add_topic.php by var_dump()'ing the values ot  $_POST["recaptcha_challenge_field"] and $_POST["recaptcha_response_field"] to confirm they are being set to what you have just typed.

Link to comment
Share on other sites

In that case, maybe try some debugging in add_topic.php by var_dump()'ing the values ot  $_POST["recaptcha_challenge_field"] and $_POST["recaptcha_response_field"] to confirm they are being set to what you have just typed.

 

How do i do that? im very new to php.

Link to comment
Share on other sites

php's website will tell you all about var_dump. All it does really is echo values to the screen.

 

Before you call the recaptcha function just add:

 

<?php
var_dump($_POST["recaptcha_challenge_field"]);
var_dump($_POST["recaptcha_response_field"]);

 

This should show what you have just typed. If it doesn't then something is most likely wrong with the HTML form.

Link to comment
Share on other sites

in advance thanks for the help :) .

 

I tried the var dump thing and i got a new error that says:

 

NULL NULL The reCAPTCHA wasn't entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol)

 

so that means for some reason or another the variables arent going in... but why would the challenge field be blank?

Link to comment
Share on other sites

Can you post a view source of your page starting at the first <form> tag to the last form tag please? Obviously remove anything identifying if you need to.

 

Those besides the home page and view forum topics page those are the only files I have. The form that is being submitted is the first code i posted and the second one is the code add the entered information to the sql.

Link to comment
Share on other sites

I've looked over the code and I can't see the issue. The php looks fine so I think it may be client side that is the problem.

 

If you have a test page that I can see feel free to pm me a link to it and I'll take a look in the morning.

Link to comment
Share on other sites

I would agree that your code looks right.  Are you 100% sure you have the right public key and private key in the scripts, and those keys match the domain you signed up for at recaptcha?  I tried out your page, and verified that it is rejecting at the recaptcha.

Link to comment
Share on other sites

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.