Recaptcha v2

Andrea Crocco

Utente Attivo
27 Apr 2016
77
0
6
salve a tutti avrei un problema da risolvere.
Come posso inserire il repatcha v2.0 su php in modo tale che l'utente sia obbligato a "farlo"?:roll:
 

Altutto

Utente Attivo
30 Set 2013
262
0
16
stubborn.altervista.org
Ciao,
Puoi utilizzare questo codice:
PHP:
<?php
session_start();
if(!isset($_POST['g-recaptcha-response'])){
	echo '<html>
	<head>
	<script src="https://www.google.com/recaptcha/api.js"></script>
	</head>
	<body>
	<form method="post" id="form" action="#">
	<input type="text" placeholder="input...">
	<div class="g-recaptcha" data-sitekey="LA TUA PUBLIC KEY"></div>
	<input type="submit" class="material-icons md-light" value="done" id="invia">
	</form>
	</body>';
}

else{
	$recaptcha_secret = "LA TUA PRIVATE KEY";
	$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$recaptcha_secret."&response=".$_POST['g-recaptcha-response']);
	$resp = json_decode($response,true);
	if($resp['success'] == true){
		echo "Verifica captcha riuscita! Ecco il codice utilizzato...";
	} 

	else {
		echo "Verifica captcha non riuscita. <input type='button' class='material-icons md-light' value='refresh' onclick='document.location.reload(true);'>";
	}

}
?>
Per provare il codice, clicca qui.
Per ottenere le tue chiavi, visita la pagina dedicata a Google ReCaptcha.
 

Andrea Crocco

Utente Attivo
27 Apr 2016
77
0
6
ciao innanzitutto grazie, però pur sostituendo l'Id del pulsante Invia creato da te il captcha non viene più verificato.
Mi potresti dire dove sbaglio?:crying:

<?php
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);
}
function RecursiveMkdir($path)
{
if (!file_exists($path))
{
RecursiveMkdir(dirname($path));
mkdir($path, 0777);
}
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['formid']) && $_POST['formid'] == 'form2')
{
$mailto = '';
$mailfrom = isset($_POST['email']) ? $_POST['email'] : $mailto;
$subject = 'commenta';
$message = '';
$success_url = './Grazie.php';
$error_url = './Errore.php';
$error = '';
$autoresponder_from = 'Admin';
$autoresponder_subject = 'Grazie!';
$autoresponder_message = 'Grazie per averci inviato il suo commento.
I commenti per noi sono molto preziosi.
Grazie!
Admin';
$eol = "\n";
$max_filesize = isset($_POST['filesize']) ? $_POST['filesize'] * 1024 : 1024000;
$upload_folder = "upload";
$upload_folder = "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME'])."/".$upload_folder;

$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>";
}

$prefix = rand(111111, 999999);

$i = 0;
while (list ($key, $val) = each ($_FILES))
{
if ($_FILES[$key]['name'] != "" and file_exists($_FILES[$key]['tmp_name']) and $_FILES[$key]['size'] > 0)
{
$upload_DstName[$i] = $prefix . "_" . str_replace(" ", "_", $_FILES[$key]['name']);
$upload_SrcName[$i] = $_FILES[$key]['name'];
$upload_Size[$i] = ($_FILES[$key]['size']);
$upload_Temp[$i] = ($_FILES[$key]['tmp_name']);
$upload_URL[$i] = "$upload_folder/$upload_DstName[$i]";
$upload_FieldName[$i] = $key;
}
if ($upload_Size[$i] >= $max_filesize)
{
$error .= "The size of $key (file: $upload_SrcName[$i]) is bigger than the allowed " . $max_filesize/1024 . " Kbytes!\n";
}
$i++;
}

if (!empty($error))
{
$errorcode = file_get_contents($error_url);
$replace = "##error##";
$errorcode = str_replace($replace, $error, $errorcode);
echo $errorcode;
exit;
}

$uploadfolder = basename($upload_folder);
for ($i = 0; $i < count($upload_DstName); $i++)
{
$uploadFile = $uploadfolder . "/" . $upload_DstName[$i];
if (!is_dir(dirname($uploadFile)))
{
RecursiveMkdir(dirname($uploadFile));
}
else
{
chmod(dirname($uploadFile), 0777);
}
move_uploaded_file($upload_Temp[$i] , $uploadFile);
chmod($uploadFile, 0644);
$name = "$" . $upload_FieldName[$i];
$message = str_replace($name, $upload_URL[$i], $message);
}

$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;
}
}
}
if (count($upload_SrcName) > 0)
{
$message .= "\nThe following files have been uploaded:\n";
for ($i = 0; $i < count($upload_SrcName); $i++)
{
$message .= $upload_SrcName[$i] . ": " . $upload_URL[$i] . "\n";
}
}
$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;
$body .= '--'.$boundary.'--'.$eol;
if ($mailto != '')
{
mail($mailto, $subject, $body, $header);
}
$autoresponder_header = 'From: '.$autoresponder_from.$eol;
$autoresponder_header .= 'Reply-To: '.$autoresponder_from.$eol;
$autoresponder_header .= 'MIME-Version: 1.0'.$eol;
$autoresponder_header .= 'Content-Type: text/plain; charset=ISO-8859-1'.$eol;
$autoresponder_header .= 'Content-Transfer-Encoding: 8bit'.$eol;
$autoresponder_header .= 'X-Mailer: PHP v'.phpversion().$eol;
mail($mailfrom, $autoresponder_subject, $autoresponder_message, $autoresponder_header);
header('Location: '.$success_url);
exit;
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Commenta</title>
<meta name="generator" content="Prova">
<link href="tuttitrucchi%20sito%20icona.png" rel="shortcut icon" type="image/x-icon">

<script>
$(document).ready(function()
{
$("#Form2").submit(function(event)
{
var isValid = $.validate.form(this);
return isValid;
});
$("#TextArea1").validate(
{
required: true,
type: 'custom',
param: /^[A-Za-zÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ \t\r\n\f0-9-]*$/,
length_min: '5',
length_max: '150',
match_id: 'Layer5',
match_text: 'Values must be identical',
color_text: '#000000',
color_hint: '#00FF00',
color_error: '#00C04E',
color_border: '#808080',
nohint: true,
font_family: 'Arial',
font_size: '13px',
position: 'centerright',
offsetx: 0,
offsety: 0,
bubble_class: 'bubbleleft',
effect: 'none',
error_text: 'Si prega di scrivere il suo Commento'
});
$("#Editbox2").validate(
{
required: true,
type: 'email',
length_min: '5',
length_max: '50',
match_id: 'Timer1',
match_text: 'Values must be identical',
color_text: '#000000',
color_hint: '#00FF00',
color_error: '#00C04E',
color_border: '#808080',
nohint: true,
font_family: 'Arial',
font_size: '13px',
position: 'centerright',
offsetx: 0,
offsety: 0,
bubble_class: 'bubbleleft',
effect: 'none',
error_text: 'Email non scritta'
});
$("#Layer4").stickylayer({orientation: 1, position: [0, 300], delay: 0, keepOriginalPos: true});
$("#Layer5").stickylayer({orientation: 1, position: [0, 350], delay: 0, keepOriginalPos: true});
$("#Layer3").stickylayer({orientation: 1, position: [0, 258], delay: 0, keepOriginalPos: true});
$("#Layer2").stickylayer({orientation: 9, position: [0, 0], delay: 0});
});
</script>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>

</head>
<body <div id="fb-root">
div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/it_IT/sdk.js#xfbml=1&version=v2.5&appId=481538242014231";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>>
<div id="wb_Shape1" style="position:absolute;left:239px;top:305px;width:950px;height:780px;z-index:10;">
<div id="Shape1"></div></div>
<div id="wb_Text5" style="position:absolute;left:740px;top:817px;width:245px;height:18px;z-index:11;text-align:left;">
<span style="color:#000000;font-family:Arial;font-size:16px;">Altro</span></div>
<div id="wb_Form2" style="position:absolute;left:476px;top:443px;width:435px;height:473px;z-index:12;">
<form name="Commenti" method="post" action="<?php echo basename(__FILE__); ?>" enctype="multipart/form-data" id="Form2">
<input type="hidden" name="formid" value="form2">
<div id="wb_Text1" style="position:absolute;left:10px;top:71px;width:119px;height:18px;z-index:0;text-align:left;">
<span style="color:#D6CFD6;font-family:Georgia;font-size:16px;"><strong>Commento:</strong></span></div>
<textarea name="Problema" id="TextArea1" style="position:absolute;left:117px;top:71px;width:299px;height:152px;z-index:1;" rows="8" cols="47"></textarea>
<input type="text" id="Editbox2" style="position:absolute;left:117px;top:23px;width:299px;height:22px;line-height:22px;z-index:2;" name="Nome" value="">
<div id="wb_Text2" style="position:absolute;left:10px;top:23px;width:57px;height:36px;z-index:3;text-align:left;">
<span style="color:#D6CFD6;font-family:Georgia;font-size:16px;"><strong>Email:</strong></span></div>
<div id="wb_Text14" style="position:absolute;left:10px;top:271px;width:100px;height:36px;z-index:4;text-align:left;">
<span style="color:#D6CFD6;font-family:Georgia;font-size:16px;"><strong>Inserire Captcha:</strong></span></div>
<div id="Html2" style="position:absolute;left:313px;top:374px;width:107px;height:43px;z-index:5">
<input type="image" src="images/active.png" title="premi per inviare" alt="submit" onclick=" ShowObject('Layer1', 1); ShowObject('Layer2', 1);TimerStartTimer1();" onmouseover="SetImage('Html2','images/hover.png');return false;"></div>
<div id="Html3" style="position:absolute;left:110px;top:249px;width:310px;height:103px;z-index:6">

<?php
session_start();
if(!isset($_POST['g-recaptcha-response'])){
echo '<html>
<head>
<script src="https://www.google.com/recaptcha/api.js"></script>
</head>
<body>
<form method="post" id="form" action="#">

<div class="g-recaptcha" data-sitekey="6LdV3x4TAAAAAK0nIUw5l0XatMRxK014M-8ctxV4"></div>

</form>
</body>';
}

else{
$recaptcha_secret = "6LdV3x4TAAAAANW0QQorcbpKf-LjoQgXxvI4boLB";
$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$recaptcha_secret."&response=".$_POST['g-recaptcha-response']);
$resp = json_decode($response,true);
if($resp['success'] == true){
echo "Verifica captcha riuscita! Ecco il codice utilizzato...";
}

else {
echo "Verifica captcha non riuscita. <input type='button' class='material-icons md-light' value='refresh' onclick='document.location.reload(true);'>";
}

}
?></div>
</form>
</div>
<div id="wb_Text7" style="position:absolute;left:518px;top:390px;width:402px;height:16px;z-index:13;text-align:left;">
<span style="color:#FF0000;font-family:'Courier New';font-size:13px;"><strong>Si prega di compilare tutti i campi richiesti</strong></span></div>
<div id="wb_Image1" style="position:absolute;left:241px;top:0px;width:950px;height:305px;z-index:14;">
<img src="images/tumblr_static_bianco7.jpg" id="Image1" alt=""></div>
<div id="Layer4" style="position:absolute;text-align:left;left:0px;top:323px;width:43px;height:50px;z-index:15;">
<div id="wb_Image8" style="position:absolute;left:0%;top:16%;width:100%;height:84%;z-index:7;">
<a href="https://instagram.com/tutti_trucchi/" target="_blank"><img src="images/instagramnormale2.png" id="Image8" alt=""></a></div>
</div>
<div id="Layer5" style="position:absolute;text-align:left;left:0px;top:373px;width:43px;height:42px;z-index:16;">
<div id="wb_Image12" style="position:absolute;left:0%;top:0%;width:100%;height:100%;z-index:8;">
<a href="https://plus.google.com/u/0/109960151560903383697" target="_blank"><img src="images/google%2B1normale2.png" id="Image12" alt=""></a></div>
</div>
<div id="Layer3" style="position:absolute;text-align:left;left:0px;top:281px;width:43px;height:50px;z-index:17;">
<div id="wb_Image13" style="position:absolute;left:0%;top:16%;width:100%;height:84%;z-index:9;">
<a href="https://www.facebook.com/inventore9" target="_blank"><img src="images/facebooknormale2.png" id="Image13" alt=""></a></div>
</div>
<div id="wb_Shape13" style="position:absolute;left:239px;top:1085px;width:951px;height:43px;z-index:18;">
<div id="Shape13"></div></div>
<marquee direction="left" scrolldelay="90" scrollamount="6" behavior="scroll" loop="0" style="position:absolute;left:249px;top:1087px;width:834px;height:40px;z-index:19;" id="Marquee1"><span style="color:#FF0000;font-family:'Comic Sans MS';font-size:27px;">Sito creato da Crocco Andrea,per maggiori info Contattatemi nella sezione &quot;Contatti&quot; posto sul menù a tendina</span></marquee>
<div id="wb_Image16" style="position:absolute;left:1102px;top:1086px;width:45px;height:41px;z-index:20;">
<a href="https://instagram.com/andre_crocco2.0/" target="_blank"><img src="images/instagrammmmmmmmmmmmmmmmmmmmm.png" id="Image16" alt=""></a></div>
<div id="wb_Image14" style="position:absolute;left:1060px;top:1086px;width:42px;height:41px;z-index:21;">
<a href="https://www.facebook.com/inventore9" target="_blank"><img src="images/fb_h.png" id="Image14" alt=""></a></div>
<div id="wb_Image15" style="position:absolute;left:1147px;top:1086px;width:42px;height:41px;z-index:22;">
<a href="https://plus.google.com/u/0/109960151560903383697" target="_blank"><img src="images/go_h.png" id="Image15" alt=""></a></div>
<div id="Html1" style="position:absolute;left:360px;top:239px;width:829px;height:66px;z-index:23">
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="index_files/mbcsmbmcp.css" />
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans">
</head>
<body>


<div id="mbmcpebul_wrapper" style="max-width: 699px;">
<ul id="mbmcpebul_table" class="mbmcpebul_menulist css_menu">
<li><div class="arrow buttonbg"><a href="index2.html">Home</a></div>
<ul>
<li><a href="TrucchiPc.html" title="">Trucchi PC</a></li>
<li><a href="TrucchiAndroid.html" title="">Trucchi Android</a></li>
</ul></li>
<li><div class="arrow buttonbg" style="width: 125px;"><a>Informazioni</a></div>
<ul>
<li><a href="Index2.html#Info" title="">Informazioni su di Me</a></li>
<li><a href="Informazioni.html" title="">Informazioni sul Sito</a></li>
</ul></li>
<li><div class="arrow buttonbg" style="width: 86px;"><a>Moduli</a></div>
<ul>
<li><a href="Contatta.php" title="">Contatta</a></li>
<li><a href="Commenta.php" title="">Commenta</a></li>
</ul></li>
<li><div class="arrow buttonbg" style="width: 123px;"><a>Windows 10</a></div>
<ul>
<li><a href="Info10.html" title="">Informazioni su Windows 10</a></li>
<li><a href="Requisiti_Windows_10.html" title="">Requisiti Windows 10</a></li>
<li><a href="Windows10.html" title="">Come Scaricare Windows 10</a></li>
</ul></li>
<li><div class="arrow buttonbg" style="width: 129px;"><a>Registrazione</a></div>
<ul>
<li><a href="Registrazione.php" title="">Registrati Gratuitamente</a></li>
<li><a href="Login.php" title="">Login</a></li>
</ul></li>
<li><div class="buttonbg" style="width: 140px;"><a href="Sistemi_operativi.php" target="_self" class="button_6">Sistemi Operativi</a></div></li>
</ul>
</div>
<!-- Menus will work without this javascript file. It is used only for extra
effects, improved usability, compatibility with very old web browsers
and support for touch screen devices. -->
<script src="index_files/mbjsmbmcp.js"></script>
</body>
</html>
</div>
<div id="Layer1" style="position:absolute;text-align:center;visibility:hidden;left:0px;top:0px;width:1438px;height:1209px;z-index:24;">
<div id="Layer1_Container" style="width:1438px;position:relative;margin-left:auto;margin-right:auto;text-align:left;">
</div>
</div>
<div id="Layer2" style="position:absolute;text-align:center;visibility:hidden;left:870px;top:578px;width:331px;height:163px;z-index:25;">
<div id="Layer2_Container" style="width:331px;position:relative;margin-left:auto;margin-right:auto;text-align:left;">
</div>
</div>
<input type="submit" id="Button1" onclick="ShowObject('Layer1', 1);ShowObject('Layer2', 1);return false;" name="" value="Submit" style="position:absolute;left:168px;top:600px;width:96px;height:25px;visibility:hidden;z-index:26;">
<script>
var wb_Timer1;
function TimerStartTimer1()
{
wb_Timer1 = setTimeout(function()
{
var event = null;
ShowObject('Layer1', 0);
ShowObject('Layer2', 0);
}, 4500);
}
function TimerStopTimer1()
{
clearTimeout(wb_Timer1);
}
</script>

</body>
</html>
 

Altutto

Utente Attivo
30 Set 2013
262
0
16
stubborn.altervista.org
Sì avevo capito grazie :) quello che intendevo è che sarebbe più semplice per me trovare eventuali errori presenti nella parte del codice interpretata dal client se mi linkassi la pagina caricata sul tuo sito
 

Altutto

Utente Attivo
30 Set 2013
262
0
16
stubborn.altervista.org
A parte il fatto che il contenitore del widget di recaptcha non è vuoto quando recaptcha è caricato, la console non segnala altri errori rilevanti, e poi riesco a mettere la spunta e ad ottenere l'ok per procedere, di conseguenza il problema è lato server.
All'inizio del tuo codice, subito dopo l'apertura del tag di php, aggiungi:
PHP:
error_reporting(E_ALL);
In questo modo, php stamperà a video eventuali errori che incontra :)
 

Andrea Crocco

Utente Attivo
27 Apr 2016
77
0
6
ti ringrazio per la disponibilità ma... non mi va ...prova a vedere anche te e a fare le prove..... ma non mi va :(

mi potresti spiegare passo passo cosa ho sbagliato e cosa aggiungere?

(ricordo che ho sostituito il tuo pulsante invia con il mio che comprende tutto il form....forse è sbagliato quello...)
 

Andrea Crocco

Utente Attivo
27 Apr 2016
77
0
6
mi spiego meglio: vorrei che al posto di visualizzare il messaggio mi porti subito ad una pagina di errore come quella del form (dovrebbe essere errore.php, adesso non mi ricordo).
che codice modifico/inserisco?
 

Altutto

Utente Attivo
30 Set 2013
262
0
16
stubborn.altervista.org
Ciao :)
Il pulsante invia non dovrebbe costituire un problema se si riferisce allo stesso form in cui c'è il captcha.
Per reindirizzare, usa
PHP:
header("Location: errore.php");
Al posto di
PHP:
echo "Verifica captcha non riuscita. <input type='button' class='material-icons md-light' value='refresh' onclick='document.location.reload(true);'>";
 

Andrea Crocco

Utente Attivo
27 Apr 2016
77
0
6
Altutto avrei un problema....inserendo il tuo codice "header("Location: errore.php");" il pulsante submit non va più
perchè???? :(
 

Discussioni simili