Aiuto per ultimazione form invio email

Lan

Nuovo Utente
5 Mar 2013
2
0
0
Ciao,
son qui per chiedere aiuto sulla creazione di un form mail con captcha e allegato. Ho già creato la pagina form e la parte php per inviare il messaggio ad un indirizzo mail.
Il codice form è il seguente:

HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
	
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	
	<title>
		Form
	</title>

</head>

<body>
	<form id="form1" enctype="multipart/form-data" method="post" action="feedback.php">
		<table width="750px" border="1" cellspacing="5" cellpadding="5">
			<tr>
				<td width="50%">
					<div align="right">
						Nome
					</div>
				</td>
				<td width="50%">
					<div align="left">
						
							<p>
								<label>
									<input name="nome" type="text" id="nome" size="40" />
								</label>
							</p>
					</div>
				</td>
			</tr>
			<tr>
				<td>
					<div align="right">
						Email
					</div>
				</td>
				<td>
					<div align="left">
							<p>
								<label>
									<input name="email" type="text" id="email" size="40" />
								</label>
							</p>
					</div>
				</td>
			</tr>
			<tr>
				<td>
					<div align="right">
						Oggetto
					</div>
				</td>
				<td>
					<div align="left">
							<p>
								<label>
									<input name="oggetto" type="text" id="oggetto" size="40" />
								</label>
							</p>
					</div>
				</td>
			</tr>
			<tr>
				<td>
					<div align="right">
						Messaggio
					</div>
				</td>
				<td>
					<div align="left">
							<p>
								<label>
									<textarea name="messaggio" id="messaggio" cols="45" rows="5"></textarea>
								</label>
							</p>
					</div>
				</td>
			</tr>
			<tr>
				<td>
					<div align="right">
						Upload File
					</div>
				</td>
				<td>
					<div align="left">
							<p>
								<label>
									<input type="file" name="upload_file" id="upload_file" />
								</label>
							</p>
					</div>
				</td>
			</tr>
			<tr>
				<td>
					<div align="right">
						Codice captcha
					</div>
				</td>
				<td>
					<div align="left">
						<img src="captcha.php" alt="captcha codice" name="captcha" width="233" height="49" id="captcha" />
					</div>
				</td>
			</tr>
			<tr>
				<td>
					<div align="right">
						Inserisci il codice captcha
					</div>
				</td>
				<td>
					<div align="left">
						<form id="form2" enctype="multipart/form-data" method="post" action="captcha.php">
							<p>
								<label>
									<input name="text_captcha" type="text" id="text_captcha" size="40" />
								</label>
							</p>
						</form>
					</div>
				</td>
			</tr>
			<tr>
				<td>
					<div align="right">
							<p>
								<input type="reset" name="reset" id="reset" value="Cancella" />
							</p>
					</div>
				</td>
				<td>
					<div align="left">
							<p>
								<input type="submit" name="invia" id="invia" value="Invia" />
							</p>
					</div>
				</td>
			</tr>
		</table>
	</form>	
	
</body>

</html>

Il codice captcha, l'ho trovato su google, è questo:

PHP:
<?php
session_start();
header("Content-type: image/png");
$captchaImage = imagecreatefrompng("captcha.png") or die("Cannot Initialize new GD image stream");
$captchaFont = imageloadfont("font.gdf");
$captchaText = substr(md5(uniqid('')),-9,9);
$_SESSION['session_captchaText'] = $captchaText;
$captchaColor = imagecolorallocate($captchaImage,200,200,200);
imagestring($captchaImage,$captchaFont,15,5,$captchaText,$captchaColor);
imagepng($captchaImage);
imagedestroy($captchaImage);
?>

Mentre il codice php, per inviare il messaggio, è questo:

PHP:
<?php
//Recupero variabili
	$nome = $_POST['nome'];
	$email = $_POST['email'];
	$oggetto = $_POST['oggetto'];
	$messaggio = $_POST['messaggio'];
	$ip = $_SERVER['REMOTE_ADDR'];
	
//Settare email
	$to = "[email protected]";

//Creazione del mesaggio da inviare
	$headers = "From: $email \n";
	$headers .= "Reply-To: $email \n";
	$headers .= "MIME-Version: 1.0 \n";
	$headers .= "Content-Type: text/html; charset=ISO-8859-1 \n";
	$message = "Hai ricevuto una e-mail da: ".$nome.", ".$email.".<br /> <br />";
	$message .= "Oggetto: ".$oggetto."<br /> <br />";
	$message .= "Messaggio: <br /> <br />".$messaggio."<br /><br /> <br />";
	$message .= "IP: ".$ip."<br /> <br />";
	
//Se l'e-mail viene spedita correttamente, compare un messaggio di avvenuto invio
	 if(mail($to, $oggetto,$message, $headers)){
		echo "<p>Messaggio inviato con successo</p>";
	}

//Altrimenti un messaggio di errore
	else{ 
		echo "<p>Ci sono stati degli errori nell'invio della e-mail. Riprovate!</p>";
	}
?>

Non so come integrare il controllo captcha e l'allegato, ma soprattutto settare i campi obbligatori, nome email oggetto messaggio e inserisci il codice captcha.

Grazie in anticipo a chiunque cerchi di darmi una mano.
 

Longo8

Utente Attivo
28 Mar 2011
1.694
0
36
Per rendere i campi obbligatori basta controllarli nella pagina php dove invii il messaggio.
Se non c'è nulla allora non invii il messaggio ma torni indietro dicendo all'utente che quei campi sono obbligatori.
 

Lan

Nuovo Utente
5 Mar 2013
2
0
0
Ciao,
grazie per la risposta. Ho fatto passi in avanti, però ora non riesco più a venirne a capo.

HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		
		<title>
			Form
		</title>
		
		<script type="text/javascript" language="JavaScript">
			<!-- 
			var watchID = null
			var watchRun = false 
			function stopwatch(){
				if(watchRun) 
					clearTimeout(watchID)
				watchRun = false
			} 
			function startwatch(){
				stopwatch()
				dayTime()
			} 
			function dayTime() {
				day = new Date();
				hour = day.getHours();
				minute = day.getMinutes();
				second = day.getSeconds();
			 
				if (hour > 12) {
					hours = hour - 12;
					part = 'PM'
				}
				else {
					part = 'AM';
					if (hour == 0) {
						hours = 12
					}
					else {
						hours = hour
					}
				} 
				if (minute < 10) {
					minutes = 0
				}
				else {
					minutes = ""
				} 
				if (second < 10) {
					seconds = 0
				}
				else {
					seconds =""
				}
				date = ('' +day.getDate()+"/"+(day.getMonth()+ 1)+"/"+(day.getYear()+ 1900)+ '');
				time = ('' + hours + ":"+minutes+""+minute+ ":"+seconds+""+second+ '')
				parts = ('' +part+ '') 
				document.timedate.time.value = time
				document.timedate.date.value = date
				document.timedate.parts.value = parts
				watchID = setTimeout("dayTime()",1000)
				watchRun = true
			}
			//-->
		</script>

	</head>

	<body onload="startwatch()">
		
		<div align="center">
			<table width="750px" height="75px" border="1">
				<tr>
					<td align="center" valign="middle">
						<table width="750px" height="75px" border="3" bordercolor="blue" cellpadding="20">
							<tr>
								<td align="center">
									<?php

										# Inizio sessione e termina gli errori
										session_start();
										error_reporting(0);
										
										# Recupero variabili
										$nome = $_POST['nome'];
										$email = $_POST['email'];
										$oggetto = $_POST['oggetto'];
										$messaggio = $_POST['messaggio'];
										$captcha = $_POST['text_captcha'];
										$ip = $_SERVER['REMOTE_ADDR'];
										$time = date('r');

										# Controlla se tutti i dati sono stati inseriti
										if 
											( 
												$nome != '' &&
												$email != '' &&
												$oggetto != '' &&
												$messaggio != '' &&
												$captcha != ''
											)
										{
											# Controlla se il codice di sicurezza è giusto
											if ( $captcha == $_SESSION['captcha'] )
												{
					
													# formatto il testo eliminando le slashes se presenti - es. D'Amico e non D/'Amico come farebbe php 
													$nome = StripSlashes ($nome);
													$oggetto = StripSlashes ($oggetto);
													$message = StripSlashes ($messagio);
												
													# To
													$to = "[email protected]";
												
													# Subject
													$subject = "Modulo proveniente dal sito tal dei tali";
												
													# Headers
													$headers = "From: $email \n";
													$headers .= "Reply-To: $email \n";
													$headers .= "MIME-Version: 1.0 \n";
													$headers .= "Content-Type: text/html; charset=ISO-8859-1 \n";
												
													# Messagge
													$message  = "Contenuto del modulo inviato il $time  :<br /> <br /> <br />";
													$message .= "Nome: $nome  .<br /> <br />";
													$message .= "Email: $email  .<br /> <br />";
													$message .= "Indirizzo IP: $ip  .<br /> <br />";
													$message .= "Oggetto: $oggetto <br /> <br />";
													$message .= "Messaggio: <br /> <br /> $messaggio <br /> <br /> <br />";
												
													# Spedisce la mail
													if 
														( 
															mail ( $to, $subject,$message, $headers )
														)
														
													echo	
														'<table width="690px" border="1">
															<tr>
																<td align="center" valign="middle">
																	<table width="690px" border="3" bordercolor="green" cellpadding="20">
																		<tr>
																			<td align="center">
																				<div align="center" style="color:green">
																					Il messaggio è stato inoltrato con successo!
																				</div>
																			</td>
																		</tr>
																	</table>
																</td>
															</tr>
														</table>';  # Il messaggio compare dopo l'esatto inoltro del messaggio
													else
														echo	
															'<table width="690px" border="1">
																<tr>
																	<td align="center" valign="middle">
																		<table width="690px" border="3" bordercolor="red" cellpadding="20">
																			<tr>
																				<td align="center">
																					<div align="center">
																						Si sono verificati dei problemi nell’invio della mail. Riprovare!
																					</div>
																				</td>
																			</tr>
																		</table>
																	</td>
																</tr>
															</table>';  # Il messaggio compare dopo che si sono verificati dei problemi
												}
											else
												echo	
													'<table width="690px" border="1">
														<tr>
															<td align="center" valign="middle">
																<table width="690px" border="3" bordercolor="red" cellpadding="20">
																	<tr>
																		<td align="center">
																			<div align="center" style="color:red">
																				Codice captcha errato. Inserire il codice corretto!
																			</div>
																		</td>
																	</tr>
																</table>
															</td>
														</tr>
													</table>';  # Il messaggio compare quando il captcha non è corretto
										}
										else
											echo	
												'<table width="690px" border="1">
													<tr>
														<td align="center" valign="middle">
															<table width="690px" border="3" bordercolor="red" cellpadding="20">
																<tr>
																	<td align="center">
																		<div align="center" style="color:red">
																			Invio dati fallito: prego riempire tutti i campi e riprocedere!
																		</div>
																	</td>
																</tr>
															</table>
														</td>
													</tr>
												</table>';  # Il messaggio compare quando non si compilano i campi indispensabili
									?>
								</td>	
							</tr>
						</table>
					</td>
				</tr>
			</table>	
			<br>
			<form id="form1" enctype="multipart/form-data" method="post" action="">
				<table width="750px" border="1">
					<tr>
						<td align="center" valign="middle">
							<table width="750px" border="3" bordercolor="blue" cellpadding="20">
								<tr>
									<tr>
										<td width="50%">
											<div align="right">
												Nome
											</div>
										</td>
										<td width="50%">
											<div align="left">
												<p>
													<label>
														<input name="nome" type="text" id="nome" size="40" />
													</label>
												</p>
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div align="right">
												Email
											</div>
										</td>
										<td>
											<div align="left">
												<p>
													<label>
														<input name="email" type="text" id="email" size="40" />
													</label>
												</p>
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div align="right">
												Oggetto
											</div>
										</td>
										<td>
											<div align="left">
												<p>
													<label>
														<input name="oggetto" type="text" id="oggetto" size="40" />
													</label>
												</p>
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div align="right">
												Messaggio
											</div>
										</td>
										<td>
											<div align="left">
												<p>
													<label>
														<textarea name="messaggio" id="messaggio" cols="45" rows="5"></textarea>
													</label>
												</p>
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div align="right">
												Codice captcha
											</div>
										</td>
										<td>
											<div align="left" valign="middle">
												<img src="captcha.php" alt="captcha codice" name="captcha" width="250px" height="100px" id="captcha" />
											</div>
										</td>
									</tr>
										<tr>
											<td>
												<div align="right">
													Inserisci il codice captcha
												</div>
											</td>
											<td>
												<div align="left">
													<form id="form2" enctype="multipart/form-data" action="captcha.php">
														<p>
															<label>
																<input name="text_captcha" type="text" id="text_captcha" size="40" />
															</label>
														</p>
													</form>
												</div>
											</td>
										</tr>
									<tr>
										<td>
											<div align="right">
											</div>
										</td>
										<td>
											<div align="left">
												<form id="timedate" name="timedate" enctype="multipart/form-data" method="post" action="">
													<p>
														<input size="7" value="" name="date" type="text" id="date" />
														<input size="7" value="" name="time" type="text" id="time" />
														<input size="7" value="" name="parts" type="text" id="parts" />
													</p>
												</form>
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div align="right">
												<p>
													<input type="reset" name="reset" id="reset" value="Cancella" />
												</p>
											</div>
										</td>
										<td>
											<div align="left">
												<p>
													<input type="submit" name="invia" id="invia" value="Invia" />
												</p>
											</div>
										</td>
									</tr>	
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</form>
			<br>
			
			<table width="750px" height="75px" border="1">
				<tr>
					<td align="center" valign="middle">
						<table width="750px" height="75px" border="3" bordercolor="blue" cellpadding="20">
							<tr>
								<td align="center">
									<?PHP

										# Imposta quì il percorso di upload.  Il percorso è relativo
										$target_path = "uploads/";

										# Messaggio di errore
										$errore = '<font color="red">C\'&egrave; stato un errore,<br><br>Ricarica la </font>';
										
										# Messaggio di nuovo upload
										$ancora = '<a href="form.php">pagina</a><font color="red">!</font>';

										# Programma
										$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
										if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) 
											{
												$dimensione=($_FILES['uploadedfile']['size'])/1000000;
												
												# Messaggio in caso di upload eseguito correttamente
												$ok = 'Il file &egrave; stato caricato<br>' . basename( $_FILES["uploadedfile"]["name"]) . "<br>" . $dimensione . ' Mb';
												
												echo 
													'<table width="250px" height="100px" border="0">
															<tr>
																<td align="center" valign="middle">
																	<table width="250px" height="100px" border="3" bordercolor="green" cellpadding="20">
																		<tr>
																			<td align="center">
																				<div align="center">'
																					.$ok.
																				'</div>
																			</td>
																		</tr>
																	</table>
																</td>
															</tr>
														</table>';
											}
										else
											echo
													'<table width="250px" height="50px" border="0">
														<tr>
															<td align="center" valign="middle">
																<table width="250px" height="50px" border="3" bordercolor="red" cellpadding="20">
																	<tr>
																		<td align="center">
																			<div align="center">'
																				.$errore."".$ancora.
																			'</div>
																		</td>
																	</tr>
																</table>
															</td>
														</tr>
													</table>';
									?>
								</td>	
							</tr>
						</table>
					</td>
				</tr>
			</table>

			<br>
			<form id="form3" enctype="multipart/form-data" method="post" action="">
				<table width="750px" border="1">
					<tr>
						<td align="center" valign="middle">
							<table width="750px" border="3" bordercolor="blue" cellpadding="20">
								<tr>
									<tr>
										<td width="50%">
											<div align="right">
												Nome
											</div>
										</td>
										<td width="50%">
											<div align="left">
												<p>
													<label>
														<input name="name" type="text" id="name" size="40" />
													</label>
												</p>
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div align="right">
												Email
											</div>
										</td>
										<td>
											<div align="left">
												<p>
													<label>
														<input name="mail" type="text" id="mail" size="40" />
													</label>
												</p>
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div align="right">
												File da caricare
											</div>
										</td>
										<td>
											<div align="left">
												<p>
													<label>								
														<input name="uploadedfile" id="uploadedfile" type="file" size="40" />
													</label>
												</p>
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div align="right">
												Inserisci il codice captcha
											</div>
										</td>
										<td>
											<div align="left">
												<p>
													<label>

													</label>
												</p>
											</div>
										</td>
									</tr>									
									<tr>
										<td>
											<div align="right">
												<p>
													<input type="reset" name="cancell" id="cancell" value="Cancella" />
												</p>
											</div>
										</td>
										<td>
											<div align="left">
												<p>
													<input type="submit" name="ok" id="ok" value="Invia" />
												</p>
											</div>
										</td>
									</tr>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</form>			
		</div>

	</body>

</html>

Ci sono 2 tabelle.

La prima tabella è un classico form con nome, email, oggetto, messaggio e captcha. Sono riuscito a farlo funzionare come volevo. Più avanti cambierò il captcha.

Mentre nella seconda tabella, ce un form con nome, email, allega file e dovrei mettere il recaptcha. L'upload del file funziona, anche se dovrei fare in modo che non sovrascrive il file se è esistente.
Non riesco a fare la parte in cui se qualcuno fa un upload sul server, mi arrivi l'email con il link, nome file e dimensione e il nominativo di chi l'ha effettuato e codice captcha.

Il codice di recaptcha che dovrei aggiungere è il seguente:

PHP:
<?php
	require_once('recaptchalib.php');

	// Get a key from https://www.google.com/recaptcha/admin/create
	$publickey = "";
	$privatekey = "";

	# the response from reCAPTCHA
	$resp = null;
	# the error code from reCAPTCHA, if any
	$error = null;

	# was there a reCAPTCHA response?
	if ($_POST["recaptcha_response_field"]) 
		{
			$resp = recaptcha_check_answer 
				($privatekey,
				$_SERVER["REMOTE_ADDR"],
				$_POST["recaptcha_challenge_field"],
				$_POST["recaptcha_response_field"]);

			if ($resp->is_valid) 
				{
					echo "You got it!";
				} 
			else 
				{
					# set the error code so that we can display it
					$error = $resp->error;
				}
	}
	echo recaptcha_get_html($publickey, $error);
?>

Invece il file recaptchalib.php è il seguente:

PHP:
<?php
	/*
	This is a PHP library that handles calling reCAPTCHA.
	
	Documentation and latest version
	http://recaptcha.net/plugins/php/
	
	Get a reCAPTCHA API Key
	https://www.google.com/recaptcha/admin/create
	
	Discussion group
    http://groups.google.com/group/recaptcha

	Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net AUTHORS:
	 
	Mike Crawford
	Ben Maurer
	
	Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
	 
	The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
	
	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
	*/

	/*
	The reCAPTCHA server URL's
	*/
	define("RECAPTCHA_API_SERVER", "http://www.google.com/recaptcha/api");
	define("RECAPTCHA_API_SECURE_SERVER", "https://www.google.com/recaptcha/api");
	define("RECAPTCHA_VERIFY_SERVER", "www.google.com");

	/*
	Encodes the given data into a query string format
	@param $data - array of string elements to be encoded
	@return string - encoded request
	*/
	function _recaptcha_qsencode ($data) 
		{
			$req = "";
			foreach ( $data as $key => $value )
			$req .= $key . '=' . urlencode( stripslashes($value) ) . '&';

			// Cut the last '&'
			$req=substr($req,0,strlen($req)-1);
			return $req;
		}

	/*
	Submits an HTTP POST to a reCAPTCHA server
	@param string $host
	@param string $path
	@param array $data
	@param int port
	@return array response
	*/
	function _recaptcha_http_post($host, $path, $data, $port = 80) 
		{
			$req = _recaptcha_qsencode ($data);

			$http_request  = "POST $path HTTP/1.0\r\n";
			$http_request .= "Host: $host\r\n";
			$http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
			$http_request .= "Content-Length: " . strlen($req) . "\r\n";
			$http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
			$http_request .= "\r\n";
			$http_request .= $req;

			$response = '';
			if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) 
				{
					die ('Could not open socket');
				}

			fwrite($fs, $http_request);

			while ( !feof($fs) )
					$response .= fgets($fs, 1160); // One TCP-IP packet
			fclose($fs);
			$response = explode("\r\n\r\n", $response, 2);

			return $response;
		}

	/*
	Gets the challenge HTML (javascript and non-javascript version).
	This is called from the browser, and the resulting reCAPTCHA HTML widget is embedded within the HTML form it was called from.
	@param string $pubkey A public key for reCAPTCHA
	@param string $error The error given by reCAPTCHA (optional, default is null)
	@param boolean $use_ssl Should the request be made over ssl? (optional, default is false)

	@return string - The HTML to be embedded in the user's form.
	*/
	function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
	{
		if ($pubkey == null || $pubkey == '') 
			{
				die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
			}
		
		if ($use_ssl) 
			{
				$server = RECAPTCHA_API_SECURE_SERVER;
			} 
			else 
				{
					$server = RECAPTCHA_API_SERVER;
				}

			$errorpart = "";
			if ($error) 
				{
				$errorpart = "&amp;error=" . $error;
				}
			return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script>

		<noscript>
			<iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/>
			<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
			<input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
		</noscript>';
	}
	
	/*
	A ReCaptchaResponse is returned from recaptcha_check_answer()
	*/
	class ReCaptchaResponse 
		{
			var $is_valid;
			var $error;
		}
		
	/*
	Calls an HTTP POST function to verify if the user's guess was correct
	@param string $privkey
	@param string $remoteip
	@param string $challenge
	@param string $response
	@param array $extra_params an array of extra variables to post to the server
	@return ReCaptchaResponse
	*/
	function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array())
		{
			if ($privkey == null || $privkey == '') 
				{
					die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
				}

			if ($remoteip == null || $remoteip == '')
				{
					die ("For security reasons, you must pass the remote ip to reCAPTCHA");
				}

			//discard spam submissions
			if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0)
				{
					$recaptcha_response = new ReCaptchaResponse();
					$recaptcha_response->is_valid = false;
					$recaptcha_response->error = 'incorrect-captcha-sol';
					return $recaptcha_response;
				}

			$response = _recaptcha_http_post 
				(
					RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify",
					array
						(
							 'privatekey' => $privkey,
							 'remoteip' => $remoteip,
							 'challenge' => $challenge,
							 'response' => $response
						) + $extra_params
				);

			$answers = explode ("\n", $response [1]);
			$recaptcha_response = new ReCaptchaResponse();

			if (trim ($answers [0]) == 'true')
				{
					$recaptcha_response->is_valid = true;
				}
			else 
				{
					$recaptcha_response->is_valid = false;
					$recaptcha_response->error = $answers [1];
				}
			return $recaptcha_response;
		}

	/*
	Gets a URL where the user can sign up for reCAPTCHA. If your application has a configuration page where you enter a key, you should provide a link using this function.
	@param string $domain The domain where the page is hosted
	@param string $appname The name of your application
	 */
	function recaptcha_get_signup_url ($domain = null, $appname = null) 
		{
			return "https://www.google.com/recaptcha/admin/create?" .  _recaptcha_qsencode (array ('domains' => $domain, 'app' => $appname));
		}

	function _recaptcha_aes_pad($val) 
		{
			$block_size = 16;
			$numpad = $block_size - (strlen ($val) % $block_size);
			return str_pad($val, strlen ($val) + $numpad, chr($numpad));
		}

	/* 
	Mailhide related code
	*/

	function _recaptcha_aes_encrypt($val,$ky)
		{
			if (! function_exists ("mcrypt_encrypt")) 
				{
					die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed.");
				}
			$mode=MCRYPT_MODE_CBC;   
			$enc=MCRYPT_RIJNDAEL_128;
			$val=_recaptcha_aes_pad($val);
			return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
		}
		
	function _recaptcha_mailhide_urlbase64 ($x) 
		{
			return strtr(base64_encode ($x), '+/', '-_');
		}

	/*
	Gets the reCAPTCHA Mailhide url for a given email, public key and private key
	*/
	function recaptcha_mailhide_url($pubkey, $privkey, $email)
		{
			if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null)
				{
					die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " . "you can do so at <a href='http://www.google.com/recaptcha/mailhide/apikey'>http://www.google.com/recaptcha/mailhide/apikey</a>");
				}

			$ky = pack('H*', $privkey);
			$cryptmail = _recaptcha_aes_encrypt ($email, $ky);
	
			return "http://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail);
		}

	/*
	 * Gets the parts of the email to expose to the user. eg, given johndoe@example,com return ["john", "example.com"]. The email is then displayed as [email protected]
	 */
	function _recaptcha_mailhide_email_parts ($email)
		{
			$arr = preg_split("/@/", $email );

			if (strlen ($arr[0]) <= 4) 
				{
					$arr[0] = substr ($arr[0], 0, 1);
				} 
			else if (strlen ($arr[0]) <= 6) 
				{
					$arr[0] = substr ($arr[0], 0, 3);
				}
			else 
				{
					$arr[0] = substr ($arr[0], 0, 4);
				}
			return $arr;
		}

	/*
	Gets html to display an email address given a public an private key. To get a key, go to:

	http://www.google.com/recaptcha/mailhide/apikey
	 */
	function recaptcha_mailhide_html($pubkey, $privkey, $email) 
		{
			$emailparts = _recaptcha_mailhide_email_parts ($email);
			$url = recaptcha_mailhide_url ($pubkey, $privkey, $email);
	
			return htmlentities($emailparts[0]) . "<a href='" . htmlentities ($url) .
			"' onclick=\"window.open('" . htmlentities ($url) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"Reveal this e-mail address\">...</a>@" . htmlentities ($emailparts [1]);
		}
?>

Grazie a chiunque cerca di darmi un aiuto
 

Longo8

Utente Attivo
28 Mar 2011
1.694
0
36
Come avrai notato è inutile e contro producente postare codice così lungo. Specifica dove è il problema e posta solo quella parte di codice.
 
Discussioni simili
Autore Titolo Forum Risposte Data
E Aiuto per query PHP 8
I aiuto urgente per thunderbird Posta Elettronica 0
I aiuto per outlook Posta Elettronica 0
T aiuto per trasformare un quiz fatto in JS in un quiz in JQUERY jQuery 0
M Fullcalendar in Codeigniter, un aiuto per la chiamata $ajax ? jQuery 0
P Aiuto per rendere un Bot Telegram Privato PHP 1
A Aiuto per pagina php PHP 0
T cercasi aiuto per file d1 (open-edge db) Database 0
L Aiuto per programma web php/mySQL PHP 2
claudio_lorenzo [Javascript] aiuto su jquery per calcolo altezze dom Javascript 1
T Aiuto per php7 e mysqli PHP 3
T mysql tutorial per importare tabelle access in mysql aiuto MySQL 2
wildcity9 aiuto per sbloccare account instagram bannati Social Media Marketing 0
A Aiuto per configurare il banner di Iubenda su un sito in html HTML e CSS 0
S [PHP] Aiuto creazione form php per completamento modello word PHP 1
Z [HTML] aiuto per visualizzazione su tablet Offerte e Richieste di Lavoro e/o Collaborazione 6
W [PHP] Un aiuto per il mio primo "Multithread" PHP 0
G Vuoi fare successo? Abbiamo bisogno di aiuto per un app! Offerte e Richieste di Lavoro e/o Collaborazione 1
K [javascript] Aiuto per programma subnetting Javascript 0
F ciao, sono ferro e ho bisogno di aiuto per problemi con la mail di alice.it Presentati al Forum 1
L [PHP] aiuto per installazione mrbs PHP 0
1 Aiuto per nuovo sito SEO e Posizionamento 4
K Server per sito di annunci: aiuto nella scelta Hosting 4
P [Javascript] Aiuto per recupero variabili da script Javascript 10
P [PHP] Aiuto per gestione file CSV PHP 24
A scambio lavoro per aiuto con android Sviluppo app per Android 0
A aiuto per un codice... PHP 1
ecosito Aiuto con la traduzione in italiano per capire come installare questo JavaScript jQuery 0
StelladelSud Cerco aiuto per una demo Offerte e Richieste di Lavoro e/o Collaborazione 3
G Piccolo aiuto per php mail PHP 2
G aiuto per semplice menu onclick HTML e CSS 6
F aiuto per funzionamento sito responsive e form contatti HTML e CSS 29
A AIUTO per impostazione doppia cifra in tabella HTML e CSS 6
G Passaggio variabili tra pagine- Aiuto per maturità 2015 PHP 3
G Passaggio variabili tra pagine- Aiuto per maturità 2015 PHP 0
A Aiuto per Flash player Flash 0
J Aiuto per localstorage con jquery/js/json Javascript 4
M Cerco aiuto per una modifica di un codice Javascript 2
A Aiuto per ordine cronologico lista file all'interno di una cartella protetta PHP 2
G Aiuto! Studente cerca aiuto per un codice PHP PHP 1
S Aiuto per 2 codifiche java Java 4
G Aiuto per creare chat stile Facebook Javascript 7
Sevenjeak Aiuto e consigli su adattamento sito per dispositivi mobile HTML e CSS 2
S aiuto per script PHP/OOP PHP 2
J Aiuto per un sitema di upload per un progetto PHP 0
K Aiuto per sito Discussioni Varie 0
D Richiesta aiuto siti per indirizzamento forum HTML e CSS 1
M Aiuto per una libreria per generare grafici PHP 1
B Saluti ed aiuto per pagina web html HTML e CSS 11
I Aiuto per modificare gruppo buddypress WordPress 0

Discussioni simili