recaptcha v2

Issues related to forms.
Post Reply
User avatar
iamafireman
 
 
Posts: 91
Joined: Mon May 26, 2008 2:41 am
Location: Tennessee

recaptcha v2

Post by iamafireman » Thu Sep 29, 2016 6:03 pm

getting a page error and page is not displayed

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/content/i/r/e/irepear/html/contact.php on line 11

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/content/i/r/e/irepear/html/contact.php on line 11

Parse error: syntax error, unexpected T_STRING in /home/content/i/r/e/irepear/html/contact.php on line 11

copied and pasted the site and secret keys, set error page, wasnt sure about tabindex so set it to zero "0"

using built in form processor, no other form on page, no added code to page.

User avatar
Pablo
 
Posts: 18676
Joined: Tue Mar 28, 2006 12:00 pm
Location: Europe
Contact:

Re: recaptcha v2

Post by Pablo » Thu Sep 29, 2016 6:05 pm

This error indicates that there is a problem is your settings.
Look for the error in line 11 of the PHP code.

Please note that this extension does not come with support.

User avatar
iamafireman
 
 
Posts: 91
Joined: Mon May 26, 2008 2:41 am
Location: Tennessee

Re: recaptcha v2

Post by iamafireman » Thu Sep 29, 2016 6:23 pm

line 11 is code generated by the extension

$recaptcha = new \ReCaptcha\ReCaptcha("secret key goes here");

User avatar
Pablo
 
Posts: 18676
Joined: Tue Mar 28, 2006 12:00 pm
Location: Europe
Contact:

Re: recaptcha v2

Post by Pablo » Thu Sep 29, 2016 8:21 pm

Maybe you have accidentally added an invalid character in your secret key?
This can only be a configuration issue.

User avatar
iamafireman
 
 
Posts: 91
Joined: Mon May 26, 2008 2:41 am
Location: Tennessee

Re: recaptcha v2

Post by iamafireman » Fri Sep 30, 2016 8:11 pm

i copied and pasted the keys directly from my recaptcha account. any other ideas?

User avatar
Pablo
 
Posts: 18676
Joined: Tue Mar 28, 2006 12:00 pm
Location: Europe
Contact:

Re: recaptcha v2

Post by Pablo » Fri Sep 30, 2016 8:41 pm

I need to see the PHP code to be able to help.

User avatar
iamafireman
 
 
Posts: 91
Joined: Mon May 26, 2008 2:41 am
Location: Tennessee

Re: recaptcha v2

Post by iamafireman » Fri Sep 30, 2016 11:37 pm

<?php
require_once './ReCaptcha/ReCaptcha.php';
require_once './ReCaptcha/RequestMethod.php';
require_once './ReCaptcha/RequestParameters.php';
require_once './ReCaptcha/Response.php';
require_once './ReCaptcha/RequestMethod/Post.php';
require_once './ReCaptcha/RequestMethod/Socket.php';
require_once './ReCaptcha/RequestMethod/SocketPost.php';
if (isset($_POST['g-recaptcha-response']))
{
$recaptcha = new \ReCaptcha\ReCaptcha("secret code here");
$response = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if (!$response->isSuccess())
{
die ("The reCAPTCHA code is incorrect. Please try again." . "(Error: " . $response->getErrorCodes() . ")");
}
}
function ValidateEmail($email)
{
$pattern = '/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i';
return preg_match($pattern, $email);
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['formid']) && $_POST['formid'] == 'form1')
{
$mailto = 'yourname@address.com';
$mailfrom = isset($_POST['email']) ? $_POST['email'] : $mailto;
$subject = 'Contact Information';
$message = 'Values submitted from web site form:';
$success_url = '';
$error_url = '';
$error = '';
$eol = "\n";
$max_filesize = isset($_POST['filesize']) ? $_POST['filesize'] * 1024 : 1024000;
$boundary = md5(uniqid(time()));
$header = 'From: '.$mailfrom.$eol;
$header .= 'Reply-To: '.$mailfrom.$eol;
$header .= 'MIME-Version: 1.0'.$eol;
$header .= 'Content-Type: multipart/mixed; boundary="'.$boundary.'"'.$eol;
$header .= 'X-Mailer: PHP v'.phpversion().$eol;
if (!ValidateEmail($mailfrom))
{
$error .= "The specified email address is invalid!\n<br>";
}
if (!empty($error))
{
$errorcode = file_get_contents($error_url);
$replace = "##error##";
$errorcode = str_replace($replace, $error, $errorcode);
echo $errorcode;
exit;
}
$internalfields = array ("submit", "reset", "send", "filesize", "formid", "captcha_code", "recaptcha_challenge_field", "recaptcha_response_field", "g-recaptcha-response");
$message .= $eol;
$message .= "IP Address : ";
$message .= $_SERVER['REMOTE_ADDR'];
$message .= $eol;
$logdata = '';
foreach ($_POST as $key => $value)
{
if (!in_array(strtolower($key), $internalfields))
{
if (!is_array($value))
{
$message .= ucwords(str_replace("_", " ", $key)) . " : " . $value . $eol;
}
else
{
$message .= ucwords(str_replace("_", " ", $key)) . " : " . implode(",", $value) . $eol;
}
}
}
$body = 'This is a multi-part message in MIME format.'.$eol.$eol;
$body .= '--'.$boundary.$eol;
$body .= 'Content-Type: text/plain; charset=ISO-8859-1'.$eol;
$body .= 'Content-Transfer-Encoding: 8bit'.$eol;
$body .= $eol.stripslashes($message).$eol;
if (!empty($_FILES))
{
foreach ($_FILES as $key => $value)
{
if ($_FILES[$key]['error'] == 0 && $_FILES[$key]['size'] <= $max_filesize)
{
$body .= '--'.$boundary.$eol;
$body .= 'Content-Type: '.$_FILES[$key]['type'].'; name='.$_FILES[$key]['name'].$eol;
$body .= 'Content-Transfer-Encoding: base64'.$eol;
$body .= 'Content-Disposition: attachment; filename='.$_FILES[$key]['name'].$eol;
$body .= $eol.chunk_split(base64_encode(file_get_contents($_FILES[$key]['tmp_name']))).$eol;
}
}
}
$body .= '--'.$boundary.'--'.$eol;
if ($mailto != '')
{
mail($mailto, $subject, $body, $header);
}
header('Location: '.$success_url);
exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Untitled Page</title>
<meta name="keywords" content="iphone repair memphis, memphis iphone repair, cracked screen iphone, ipad repair, ipod repair, jailbreak, unlock">
<meta name="author" content="www.youonthenetyet.com">
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon">
<style type="text/css">
div#container
{
width: 990px;
position: relative;
margin: 0 auto 0 auto;
text-align: left;
}
body
{
background-color: #FFFFFF;
color: #000000;
font-family: "Times New Roman";
font-weight: normal;
font-size: 21px;
line-height: 1.1875;
margin: 0;
text-align: center;
}
a
{
color: #0000FF;
text-decoration: underline;
}
a:active
{
color: #C0C0C0;
}
a:hover
{
color: #C0C0C0;
text-decoration: underline;
}
#wb_Form1
{
background-color: #FFFFFF;
background-image: none;
border: 1px #CCCCCC solid;
}
#Label1
{
border: 0px #CCCCCC solid;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
background-color: transparent;
background-image: none;
color :#000000;
font-family: "Times New Roman";
font-weight: normal;
font-size: 21px;
padding: 4px 4px 4px 4px;
text-align: left;
vertical-align: middle;
}
#Editbox1
{
border: 1px #CCCCCC solid;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
background-color: #FFFFFF;
background-image: none;
color :#000000;
font-family: "Times New Roman";
font-weight: normal;
font-size: 21px;
padding: 4px 4px 4px 4px;
text-align: left;
vertical-align: middle;
}
#Editbox1:focus
{
border-color: #66AFE9;
-webkit-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.075), 0px 0px 8px rgba(102,175,233,0.60);
-moz-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.075), 0px 0px 8px rgba(102,175,233,0.60);
box-shadow: inset 0px 1px 1px rgba(0,0,0,0.075), 0px 0px 8px rgba(102,175,233,0.60);
outline: 0;
}
#Label2
{
border: 0px #CCCCCC solid;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
background-color: transparent;
background-image: none;
color :#000000;
font-family: "Times New Roman";
font-weight: normal;
font-size: 21px;
padding: 4px 4px 4px 4px;
text-align: left;
vertical-align: middle;
}
#Editbox2
{
border: 1px #CCCCCC solid;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
background-color: #FFFFFF;
background-image: none;
color :#000000;
font-family: "Times New Roman";
font-weight: normal;
font-size: 21px;
padding: 4px 4px 4px 4px;
text-align: left;
vertical-align: middle;
}
#Editbox2:focus
{
border-color: #66AFE9;
-webkit-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.075), 0px 0px 8px rgba(102,175,233,0.60);
-moz-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.075), 0px 0px 8px rgba(102,175,233,0.60);
box-shadow: inset 0px 1px 1px rgba(0,0,0,0.075), 0px 0px 8px rgba(102,175,233,0.60);
outline: 0;
}
#Button1
{
border: 1px #2E6DA4 solid;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
background-color: #3370B7;
background-image: none;
color: #FFFFFF;
font-family: "Times New Roman";
font-weight: normal;
font-size: 21px;
}
</style>
<script src="https://www.google.com/recaptcha/api.js?hl=en" async="" defer=""></script>
</head>
<body>
<div id="container">
<div id="wb_Form1" style="position:absolute;left:192px;top:28px;width:495px;height:340px;z-index:6;">
<form name="contact" method="post" action="<?php echo basename(__FILE__); ?>" enctype="multipart/form-data" id="Form1">
<input type="hidden" name="formid" value="form1">
<label for="Editbox1" id="Label1" style="position:absolute;left:205px;top:14px;width:53px;height:25px;line-height:25px;z-index:0;">Name:</label>
<input type="text" id="Editbox1" style="position:absolute;left:276px;top:14px;width:190px;height:25px;line-height:25px;z-index:1;" name="name" value="">
<label for="Editbox2" id="Label2" style="position:absolute;left:205px;top:54px;width:53px;height:25px;line-height:25px;z-index:2;">Email:</label>
<input type="text" id="Editbox2" style="position:absolute;left:276px;top:54px;width:190px;height:25px;line-height:25px;z-index:3;" name="email" value="">
<input type="submit" id="Button1" name="" value="Send" style="position:absolute;left:187px;top:277px;width:96px;height:25px;z-index:4;">
<div id="wb_Extension1" style="position:absolute;left:113px;top:142px;width:302px;height:76px;z-index:5;">
<div class="g-recaptcha" data-sitekey="6Le5FggUAAAAAFe3IJSBIco0EbKFvpQ7HdX0jxq9"></div>
</div>
</form>
</div>
</div>
</body>
</html>

User avatar
Pablo
 
Posts: 18676
Joined: Tue Mar 28, 2006 12:00 pm
Location: Europe
Contact:

Re: recaptcha v2

Post by Pablo » Sat Oct 01, 2016 7:36 am

Can you please leave your 'secret code', because that is where is goes wrong.
All other code is correct.

User avatar
iamafireman
 
 
Posts: 91
Joined: Mon May 26, 2008 2:41 am
Location: Tennessee

Re: recaptcha v2

Post by iamafireman » Sat Oct 01, 2016 2:03 pm

<?php
require_once './ReCaptcha/ReCaptcha.php';
require_once './ReCaptcha/RequestMethod.php';
require_once './ReCaptcha/RequestParameters.php';
require_once './ReCaptcha/Response.php';
require_once './ReCaptcha/RequestMethod/Post.php';
require_once './ReCaptcha/RequestMethod/Socket.php';
require_once './ReCaptcha/RequestMethod/SocketPost.php';
if (isset($_POST['g-recaptcha-response']))
{
$recaptcha = new \ReCaptcha\ReCaptcha("6Le5FggUAAAAANachBD9R4lAvyBAxMW0TdHgB_kH");
$response = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if (!$response->isSuccess())
{
die ("The reCAPTCHA code is incorrect. Please try again." . "(Error: " . $response->getErrorCodes() . ")");
}
}
function ValidateEmail($email)
{
$pattern = '/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i';
return preg_match($pattern, $email);
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['formid']) && $_POST['formid'] == 'form1')

User avatar
Pablo
 
Posts: 18676
Joined: Tue Mar 28, 2006 12:00 pm
Location: Europe
Contact:

Re: recaptcha v2

Post by Pablo » Sat Oct 01, 2016 2:07 pm

I do not see any errors in the code.
Did you publish all files (and in the right folder)?

User avatar
iamafireman
 
 
Posts: 91
Joined: Mon May 26, 2008 2:41 am
Location: Tennessee

Re: recaptcha v2

Post by iamafireman » Sat Oct 01, 2016 3:07 pm

I did publish all files. No separate folder just the main folder that the rest of the site is published. Are ther any other files that need to be published to the server?

User avatar
Pablo
 
Posts: 18676
Joined: Tue Mar 28, 2006 12:00 pm
Location: Europe
Contact:

Re: recaptcha v2

Post by Pablo » Sat Oct 01, 2016 3:45 pm

All the files generated by the extension need to be published/uploaded:

Code: Select all

require_once './ReCaptcha/ReCaptcha.php';
require_once './ReCaptcha/RequestMethod.php';
require_once './ReCaptcha/RequestParameters.php';
require_once './ReCaptcha/Response.php';
require_once './ReCaptcha/RequestMethod/Post.php';
require_once './ReCaptcha/RequestMethod/Socket.php';
require_once './ReCaptcha/RequestMethod/SocketPost.php';

User avatar
iamafireman
 
 
Posts: 91
Joined: Mon May 26, 2008 2:41 am
Location: Tennessee

Re: recaptcha v2

Post by iamafireman » Sat Oct 01, 2016 6:12 pm

those files are on server and in that structure

User avatar
Pablo
 
Posts: 18676
Joined: Tue Mar 28, 2006 12:00 pm
Location: Europe
Contact:

Re: recaptcha v2

Post by Pablo » Sat Oct 01, 2016 8:15 pm

In that case I do not know why it does work for you.
There is no error in the code as far as I can tell.

jbWishmaster
 
 
Posts: 1
Joined: Mon Oct 31, 2016 7:50 am

Re: recaptcha v2

Post by jbWishmaster » Mon Oct 31, 2016 8:04 am

Hi. I had the same problem
My Fix. I changed the PHP version in my domain settings.

php version 5.2.17 did not work so i changed it to 5.3.29
Which then worked for me.

Post Reply