captcha code

Status
Niet open voor verdere reacties.

emielee

Gebruiker
Lid geworden
21 okt 2009
Berichten
17
Hoi Helpmij.nl,

Ik loop tegen een probleem op.. min captcha code werkt pas nadat hij word gerefresht dmv javascript.. zien jullie het probleem..
Offerte.php het formulier(het yourmail.com heb ik er ingezet zodat jullie niet dat email zien
PHP:
<?php
$your_email ='yourmail@yourmail.com';

session_start();
$errors = '';
$name = '';
$visitor_email = '';
$user_message = '';

if(isset($_POST['submit']))
{
	$name = $_POST['name'];
	$visitor_tussen=$_POST['tussen'];
	$visitor_achter=$_POST['achter'];
	$visitor_tel=$_POST['tel'];
	$visitor_mob=$_POST['mob'];
	$visitor_email = $_POST['email'];
	$user_message = $_POST['message'];
	$soort=$_POST['soort'];
	$seo = $_POST['seo'];
	$pages = $_POST['pagina'];
	$onderhoud = $_POST['onderhoud'];

	///------------Do Validations-------------
	if(empty($name)||empty($visitor_achter)|| empty($visitor_email)||empty($user_message))
	{
		$errors .= "\n Er zijn verplichte velden ";	
	}
	if(IsInjected($visitor_email))
	{
		$errors .= "\n Bad email value!";
	}
	if(empty($_SESSION['6_letters_code'] ) ||
	  strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
	{

		$errors .= "\n De validatie code komt niet overeen!";
	}
	
	if(empty($errors))
	{
		$to = $your_email;
		$from = $visitor_email;
		$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
		
		$body = "Er is een mail binnen gekomen van:  $name $visitor_tussen $visitor_achter :\n".
		"E-mail: $visitor_email \n".
		"Zoekmachine Optimalisatie:$seo \n".
		"Telefoon nummer: $visitor_tel \n".
		"Mobiel nummer: $visitor_mob \n".
		"Aantal pagina's: $pages \n".
		"Soort website: $soort \n".
		"Onderhoud: $onderhoud \n".
		"Wensen: $user_message\n".
		"IP: $ip\n";	
		
		$headers = "From: $from \r\n";
		$headers .= "Reply-To: $visitor_email \r\n";
		
		mail($to, $subject, $body,$headers);
		
		header('Location: diensten.php');
	}
}

function IsInjected($str)
{
  $injections = array('(\n+)',
              '(\r+)',
              '(\t+)',
              '(%0A+)',
              '(%0D+)',
              '(%08+)',
              '(%09+)'
              );
  $inject = join('|', $injections);
  $inject = "/$inject/i";
  if(preg_match($inject,$str))
    {
    return true;
  }
  else
    {
    return false;
  }
}
?>
<?php 
$your_email2 ='youremail@youremail.com';

session_start();
$tel = '';
$errors2 = '';

if(isset($_POST['submit2']))
{
	
	$tel = $_POST['tel'];
	

	///------------Do Validations-------------
	if(empty($tel))
	{
		$errors2 .= "\n Er zijn verplichte velden ";	
	}
	if(empty($_SESSION['6_letters_code'] ) ||
	  strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
	{

		$errors2 .= "\n De validatie code komt niet overeen!";
	}
	
	if(empty($errors2))
	{
		$to2 = $your_email2;
		$subject2="Bel me terug";
		$from2 = $tel;
		$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
	
		$body2 = "Er is een mail binnen gekomen van:\n".
		"Telefoon: $tel\n".
		"IP: $ip\n";	
		

		mail($to2, $subject2, $body2, $headers2);
		
		header('Location: bedankt.php');
	}
}
function test($str2)
{
  $injections2 = array('(\n+)',
              '(\r+)',
              '(\t+)',
              '(%0A+)',
              '(%0D+)',
              '(%08+)',
              '(%09+)'
              );
  $inject2 = join('|', $injections2);
  $inject2 = "/$inject/i";
  if(preg_match($inject2,$str2))
    {
    return true;
  }
  else
    {
    return false;
  }

}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="shortcut icon" href="images/favicon.ico"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Webdesign van Leeuwen | Contact</title>
<meta name="description" content="Webdesign van Leeuwen">
<meta name="keywords" content="web, webdesign, Webdesign, van, Van, Leeuwen, leeuwen, van Leeuwen, van leeuwen, Van Leeuwen, Design, Webdesign-vanleeuwen, Website, webdesign-vanleeuwen, WebDesign-VanLeeuwen, Webdesign-vanLeeuwen, Heerhugowaard, regio, Noord, noord, zoekmachine, optimalisatie, van leeuwen webdesign">
<meta name="author" content="Webdesign van Leeuwen">
<link rel="stylesheet" href="css/style.css" type="text/css" />
</head>
<body id="home">
<div id="wrapper">
	<div id="subwrapper">
		<div id="header">
			<div id="logo">
				<a href="./"><img src="images/logo.png" alt="Webdesign van Leeuwen"></a>
			</div>		    
				<?php
				include 'weer.php';
				?>
			<div id="menucontainer">
				<div id="menu">
					<ul id="navlist">
						<li><a href="index.php">Home</a></li>
						<li><a href="portfolio.php">Portfolio</a></li>
						<li><a href="about-us.php">Over Ons</a></li>
						<li class="current_page_item"><a href="diensten.php">Diensten</a></li>
						<li><a href="contact.php">Contact</a></li>
					</ul>
				</div>
	
			</div> 
		<div id="content">
			<div id="containerleft">

			<div id="contact">

							<?php
if(!empty($errors)){
echo "<p class='err'>".nl2br($errors)."</p>";
}
?>
<div id='contact_form_errorloc' class='err'></div>

<h1>Offerte:</h1>
<form method="POST" name="contact_form" 
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> 
<table>
	<tr>	
		De velden met een * zijn verplicht
	</tr>
	<tr>
<td width="250"	>Voorletters*: </td>
<td><input id="name" type="text" name="name" value='<?php echo htmlentities($name) ?>'></td>
</tr>
<tr>
<td>Tussenvoegsel:</td>
<td><input type="text" name="tussen" value='<?php echo htmlentities($visitor_tussen) ?>'></td>
</tr>
<tr>
<td>Achternaam*:</td>
<td><input type="text" name="achter" value='<?php echo htmlentities($visitor_achter) ?>'></td>
</tr>
<tr>
<td>E-mail*:</td>
<td><input type="email" name="email" value='<?php echo htmlentities($visitor_email) ?>'></td>
</tr>
<tr>
<td>Telefoon*:</td>
<td><input type="text" name="tel" value='<?php echo htmlentities($visitor_tel) ?>'></td>
</tr>
<tr>
<td>Mobiel:</td>
<td><input type="text" name="mob" value='<?php echo htmlentities($visitor_mob) ?>'></td>
</tr>
<tr>
<td>Zoekmachine optimalisatie*:</td>
<td><input type="radio" name="seo" value="Ja">Ja<br>
	<input type="radio" name="seo" value="Nee">Nee</td>
</tr>
<tr>
<td>Onderhoud*:</td>
<td><input type="radio" name="onderhoud" value="zelf">Zelf onderhouden<br>
	<input type="radio" name="onderhoud" value="laten">Laten onderhouden</td>
<tr>
<td>Aantal Pagina's*:</td>
<td><input type="radio" name="pagina" value="1-10">1 - 10<br>
	<input type="radio" name="pagina" value="11-15">11 - 15<br>
	<input type="radio" name="pagina" value="15ofmeer">Meer dan 15 Pagina's</td>
</tr>
<td>Soort website*:</td>
<td><input type="radio" name="soort" value="html css php mysql">HTML, CSS, PHP, MySQL<br>
	<input type="radio" name="soort" value="Joomla">Joomla<br>
	<input type="radio" name="soort" value="Wordpress">Wordpress</td>
</tr>
<tr>
<td>Welke funcitionaliteit wenst u*:</td>
<td><textarea name="message" rows=4 cols=16><?php echo htmlentities($user_message) ?></textarea></td>
</tr>
<tr>
	<td></td>
	<td><img src="validatie.php?rand=<?php echo rand(); ?>" id='captchaimg' height="25"></td>
</tr>
<tr>
	<td></td>
	<td><small id="refresh">Kunt u het niet lezen klik <a href='javascript: refreshCaptcha();'>hier</a> om de code te verversen</small></td>
</tr>
<tr>
	<td>Validatie code*:</td>
	<td><input id="6_letters_code" name="6_letters_code" type="text"></td>
</tr>
<tr>
	<td></td>
	<td><input id="submit" type="submit" value="" name='submit'></td>
</tr>
</table>
</form>

<script language="JavaScript">

var frmvalidator  = new Validator("contact_form");
frmvalidator.EnableOnPageErrorDisplaySingleBox();
frmvalidator.EnableMsgsTogether();

frmvalidator.addValidation("name","req","U heeft uw voorletters niet ingevult"); 
frmvalidator.addValidation("achter","req","U heeft uw achternaam niet ingevult");
frmvalidator.addValidation("email","req","U heeft uw e-mail adres niet ingevult"); 
frmvalidator.addValidation("message","req","U heeft geen bericht achtergelaten");  
frmvalidator.addValidation("email","email","Vul een geldig E-mail adres in");
frmvalidator.addValidation("6_letters_code","req","U heeft de validatie code niet ingevult");

</script>
<script language='JavaScript' type='text/javascript'>
function refreshCaptcha()
{
	var img = document.images['captchaimg'];
	img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
}
</script>
</div>
			</div>
			<div id="containerright">
				
				<div id="contact-gegevens">
					
					<h1>Contactgegevens</h1>
					<p>
						Webdesign van Leeuwen<br>
						H. Henriquez Pimenteltuin 20<br>
						1705 HW Heerhugowaard<br>
						06 - 25 57 19 92<br>
						<a href="http://www.webdesign-vanleeuwen.nl">www.webdesign-vanleeuwen.nl</a><br>
						
					</p>
					<h2></h2>
				</div>
		<div id="twitter-widget">
			<h1> Tweets</h1>
			<?php
$doc = new DOMDocument();
 
# load the RSS document, edit this line to include your username or user id
if($doc->load('http://twitter.com/statuses/user_timeline/Web_van_Leeuwen.rss')) {
        
       
        $max_tweets = 3;    
        
        $i = 1;
        foreach ($doc->getElementsByTagName('item') as $node) {
                # fetch the title from the RSS feed. 
                # Note: 'pubDate' and 'link' are also useful (I use them in the sidebar of this blog)
                $tweet = $node->getElementsByTagName('title')->item(0)->nodeValue;
                
                # the title of each tweet starts with "username: " which I want to remove
                $tweet = substr($tweet, stripos($tweet, ':') + 1);   
                
                # OPTIONAL: turn URLs into links
                $tweet = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', '<br /><a href="$1" target="_blanc">$1</a>', $tweet);
                
                # OPTIONAL: turn @replies into links
                $tweet = preg_replace("/@([0-9a-zA-Z]+)/", "<a href=\"http://twitter.com/$1\">@$1</a>", $tweet);
                
                echo "<p>"."<img src='images/bird.jpg' align='left'>".$tweet."</p>\n";
					
                
                if ($i++ >= $max_tweets)
                        break;
        }
        echo "</ul>\n";
} 
?>		
<h2></h2> 	
<div id="bel-me-terug">
	<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
	<h1>Bel me Terug</h1>
	<p>
		Nummer:<input type="tel2" name="tel" size="15" value="<?php echo htmlentities($tel) ?>"><br>
		<img src="validatie.php?rand=<?php echo rand(); ?>" id='captchaimg' height="25"><br>
		Validatie code:<input id="6_letters_code" name="6_letters_code" type="text" size="15"><br>
		<input class="submit" type="submit" value="" name='submit2'>
		
	</p>
		
	<h2></h2>
	</form>
</div>	
		</div>
			</div>
			<div class="clear"></div>
			<div class="pushfooter"></div> 
			<div id="footer">
				<div id="footertext">
					&copy;
					<?php 
					echo date('Y');
					?>
					| Designed by <a href="index.php">Webdesign van Leeuwen</a> |
					<?php
					
					$copyYear= 2010;					
					$curYear=date('Y');
					
					if($curYear==$copyYear){
						echo "Bestaat Since ".$copyYear;
					}
					else{
						echo "Bestaat Since ".$copyYear. ' - ' .$curYear;
					}
				
					?>
				</div>
				<div id="social">
					<div id="feed">
						<a href="#"><img src="images/social/feed.png"`target="_blanc" alt="RSS Feed"></a> 
					</div>
					<div id="linkedin">
						<a href="http://www.linkedin.com/profile/view?id=155250969&trk=tab_pro" target="_blanc"><img src="images/social/linkedin.png" alt="LinkedIN"></a>
					</div>
					<div id="twitter">
					 	<a href="https://twitter.com/intent/user?screen_name=Web_van_Leeuwen" target="_blanc"><img src="images/social/twitter.png" alt="Twitter"></a>
					 </div>
			 		<div id="hyves">
					 	<a href="http://web-van-leeuwen.hyves.nl/"><img src="images/social/hyves.png" alt="Hyves"></a>
			</div>
		</div>
	</div>
</div>
</div>
</body>
</html>
de validatie code.
PHP:
<?php 

session_start();

$image_width = 120;
$image_height = 25;
$characters_on_image = 4;
$font = 'monofont.ttf';

$possible_letters = '123456789';
$random_dots = 0;
$random_lines = 0;
$captcha_text_color="#006996";
$captcha_noice_color = "0x142864";

$code = '';


$i = 0;
while ($i < $characters_on_image) { 
$code .= substr($possible_letters, mt_rand(0, strlen($possible_letters)-1), 1);
$i++;
}


$font_size = $image_height * 0.75;
$image = @imagecreate($image_width, $image_height);


/* setting the background, text and noise colours here */
$background_color = imagecolorallocate($image, 255, 255, 255);

$arr_text_color = hexrgb($captcha_text_color);
$text_color = imagecolorallocate($image, $arr_text_color['red'], 
		$arr_text_color['green'], $arr_text_color['blue']);

$arr_noice_color = hexrgb($captcha_noice_color);
$image_noise_color = imagecolorallocate($image, $arr_noice_color['red'], 
		$arr_noice_color['green'], $arr_noice_color['blue']);


for( $i=0; $i<$random_dots; $i++ ) {
imagefilledellipse($image, mt_rand(0,$image_width),
 mt_rand(0,$image_height), 2, 3, $image_noise_color);
}



for( $i=0; $i<$random_lines; $i++ ) {
imageline($image, mt_rand(0,$image_width), mt_rand(0,$image_height),
 mt_rand(0,$image_width), mt_rand(0,$image_height), $image_noise_color);
}



$textbox = imagettfbbox($font_size, 0, $font, $code); 
$x = ($image_width - $textbox[4])/2;
$y = ($image_height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $font , $code);



header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
$_SESSION['6_letters_code'] = $code;

function hexrgb ($hexstr)
{
  $int = hexdec($hexstr);

  return array("red" => 0xFF & ($int >> 0x10),
               "green" => 0xFF & ($int >> 0x8),
               "blue" => 0xFF & $int);
}
?>
 
ik zie niet direct het probleem. Maar wanneer je hem werkend krijgt nadat je met javascript een refresh geeft, is het dan geen idee om deze refresh functie te starten wanneer de pagina wordt geladen?
 
dat zou ook kkunnen maar dat is niet goed. hijzou moeten werken zonder die refresh... en dat deed ie gister avond ook nog.. weetniet wat er nou mis was:P maar alsnog bedankt...
 
wat ik uit je javascript lees, moet je random getal tussen de 0 en 1000 liggen,
probeer eens <?php echo rand(0, 1000); ?>

ik zie alleen in je validatie script geen $_GET['rand'] staan. Heb je in dat script soms een regel verwijderd!
 
Laatst bewerkt:
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan