open captcha error message in a spesifyed file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
RexRon
Forum Newbie
Posts: 2
Joined: Wed Dec 21, 2011 6:35 am

open captcha error message in a spesifyed file

Post by RexRon »

Hello.

I have a contact form with captcha.
Some of the fields in the form are validated in a php file and the user is sent to a spesifyed file on submit.

However, I have a captcha script as well and this is checked in the same php file. If the code is entered incorrectly a message is displayed in a blank window. What I´d like is for the error message to be displayed in a css div in a spesifyed file. Can anyone help me with this?

Heres the online fom: http://www.eterya.com/Test/contact.php

Heres the part of the php file wich sends the erroor message

Code: Select all

include_once("wsp_captcha.php");

if (WSP_CheckImageCode() != "OK") {
    die("The image code you have entered is incorrect. Please, click the 'Back' button of your browser and type the correct one.");
}
Sincerely
Ronny
RexRon
Forum Newbie
Posts: 2
Joined: Wed Dec 21, 2011 6:35 am

Re: open captcha error message in a spesifyed file

Post by RexRon »

OK... Getting somewhere all though slowly :-) But I now have two problems...

1. I see now that the code I reffered to is telling the script to include a file. wsp_captcha.php.
I managed to wrap some html divs around the code but the message will not appear where it should. It appears at the bottom of the page. Try the link above to see what I mean...

2. Since I put the the include wsp_captcha.php in the error checking file, the page for the mail sent does not appear.

Any Idea how to solve this, anyone?

Here are the files:

mailresult.php:

Code: Select all

<?php
# ----------------------------------------------------
# -----
# ----- This script was generated by PHP-Form Wizard 1.2.5 on 19.12.2011 at 22:44:33
# -----
# ----- http://www.tools4php.com
# -----
# ----------------------------------------------------


// Receiving variables
@$pfw_ip= $_SERVER['REMOTE_ADDR'];
@$navn = addslashes($_POST['navn']);
@$etternavn = addslashes($_POST['etternavn']);
@$bedrift = addslashes($_POST['bedrift']);
@$epost = addslashes($_POST['epost']);
@$telefon = addslashes($_POST['telefon']);
@$melding = addslashes($_POST['melding']);
@$submit = addslashes($_POST['']);

// Validation
if (strlen($navn) == 0 )
{
header("Location: contactError.php");
exit;
}

if (strlen($etternavn) == 0 )
{
header("Location: contactError.php");
exit;
}

if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $epost))
{
header("Location: contactError.php");
exit;
}

if (strlen($epost) == 0 )
{
header("Location: contactError.php");
exit;
}

include_once("wsp_captcha.php");

if (WSP_CheckImageCode() != "OK") {
    die("The image code you have entered is incorrect. Please, click the 'Back' button of your browser and type the correct one.");
}


//Sending Email to form owner
$pfw_header = "From: $navn\n"
  . "Reply-To: $navn\n";
$pfw_subject = "Kundeforespørsel";
$pfw_email_to = "ronny@eterya.com";
$pfw_message = "Visitor's IP: $pfw_ip\n"
. "Fornavn: $navn\n"
. "Etternavn: $etternavn\n"
. "Bedrift: $bedrift\n"
. "epost: $epost\n"
. "Telefon: $telefon\n"
. "Melding: $melding\n"
. "\n";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

//Sending auto respond Email to visitor
$pfw_header = "From: mymail@mymail.com\n"
  . "Reply-To: mymail@mymail.com\n";
$pfw_subject = "Eterya Design";
$pfw_email_to = "$epost";
$pfw_message = "Hei.\n"
. "\n"
. "Vi takker for din forespørsel. Vi vil høre fra oss så snart som mulig og senest inne 24 timer.\n"
. "\n"
. "Ha en super dag...\n"
. "\n"
. "Vennlig hilsen\n"
. "Eterya Design";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

//saving record in a text file
$pfw_file_name = "kundemail.txt";
$pfw_first_raw = "navn;etternavn;bedrift;epost;telefon;melding\r\n";
$pfw_values = "$navn;$etternavn;$bedrift;$epost;$telefon;".str_replace ("\r\n","<BR>",$melding )."\r\n";
$pfw_is_first_row = false;
if(!file_exists($pfw_file_name))
{
 $pfw_is_first_row = true ;
}
if (!$pfw_handle = fopen($pfw_file_name, 'a+')) {
 die("Cannot open file ($pfw_file_name)");
 exit;
}
if ($pfw_is_first_row)
{
  if (fwrite($pfw_handle, $pfw_first_raw ) === FALSE) {
  die("Cannot write to file ($pfw_filename)");
  exit;
  }
}
if (fwrite($pfw_handle, $pfw_values) === FALSE) {
  die("Cannot write to file ($pfw_filename)");
  exit;
}
fclose($pfw_handle);

header("Location: contactSuccess.php");

?>
wsp_captcha.php:

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="layout.css" rel="stylesheet" type="text/css" />
<link href="contact.css" rel="stylesheet" type="text/css" />
<meta name="Keywords" content="Webdesign, Nettannonser, Nettbutikk, Billig, Rimelig, Proff" />
<meta name="Description" content="Eterya Design produserer websider og nettannonser til en rimelig pris. Setter også opp OsCommerce nettbutikk på din server. Det meste til en overkommelig pris." />
<title>Eterya Design - Webdesign</title></head>

<body>

 <!-- Begin Wrapper -->
<div id="wrapper">
   
         <!-- Begin Header -->

		 <div id="header">
		   <?php require("header_contact.php"); ?><div>
		 <!-- End Header -->
		 
		 <!-- Begin Content -->
		 <div id="content">
		   <div id="MainContact">  
           <div id="AdresseBoks"><span class="StandardGrayBold">Postadresse</span><br/><span class="SmallDark">Eterya Design<br/>Brudeberget 1<br/>3055<br/>Krokstadelva</span><br/><br/>
           
           <span class="StandardGrayBold">Telefon</span><br/><span class="SmallDark">+47 957 00 224<br/><br/>
           
           </span><span class="StandardGrayBold">E-post<br/></span><span class="SmallDark">post@eterya.com</span></div>
       <div id="MailResult">
<?php
/*-------------------------------------------------------------------------------
         Copyrights 2006-2007 (c) WebSpamProtect.com
		 Filename : wsp_captcha.php
		 Version  : 1.2
 -------------------------------------------------------------------------------*/

/* This function will check captcha code entered by user and stop spam robots */
function WSP_CheckImageCode($WSP_ImgKey = '', $WSP_ImgCode = '') {
	if (!$WSP_ImgKey) {
		if (isset($_POST['wsp_key'])) $WSP_ImgKey = $_POST['wsp_key'];
		elseif (isset($_GET['wsp_key'])) $WSP_ImgKey = $_GET['wsp_key'];
	}
	if (!$WSP_ImgCode) {
		if (isset($_POST['wsp_code'])) $WSP_ImgCode = $_POST['wsp_code'];
		elseif (isset($_GET['wsp_code'])) $WSP_ImgCode = $_GET['wsp_code'];
	}

	if (!$WSP_ImgKey || (strlen($WSP_ImgKey) > 32)) return "Error: 'wsp_key' is invalid.";
	if (!$WSP_ImgCode || (strlen($WSP_ImgCode) > 10)) return "Error: 'wsp_code' is invalid.";

	$WSP_Params = "&imgkey=".urlencode($WSP_ImgKey)."&imgcode=".urlencode($WSP_ImgCode);
	$WSP_Result = WSP_GetData('checkcode.php', $WSP_Params);

	switch(intval($WSP_Result)) {
	case 200 :
		return "OK";
		break;
	case 404 :
		return "Error: The image code entered by user is invalid.";
		break;
	case 401 :
		return "Error: You are not authorized to use WebSpamProtect.com service.";
		break;
	case 501 :
		return "Error: It appears that your web host has disabled all functions for handling remote pages and as a result the WebSpamProtect.com software will not function on your web page. Please contact your web host for more information.";
		break;
	default :
		return "Unknown error.";
		break;
	}
}

function WSP_GetData($WSP_File = '', $WSP_Params = '') {
	$WSP_UserKey = "QP4A-N6Y3-O61B-BLD6";
	$WSP_Version = "1.2";
	if (!$WSP_UserKey) return 401;
	$WSP_URL = "http://webspamprotect.com/".$WSP_File."?ver=".urlencode($WSP_Version)."&userkey=".urlencode($WSP_UserKey).$WSP_Params;

	if ((intval(get_cfg_var('allow_url_fopen')) || intval(ini_get('allow_url_fopen'))) && function_exists('file_get_contents')) {
		$WSP_Result = @file_get_contents($WSP_URL);
	} elseif ((intval(get_cfg_var('allow_url_fopen')) || intval(ini_get('allow_url_fopen'))) && function_exists('file')) {
		$content = @file($WSP_URL);
		$WSP_Result = @join('', $content);
	} elseif (function_exists('curl_init')) {
		$ch = curl_init($WSP_URL);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		$WSP_Result = curl_exec($ch);
		curl_close($ch);
	} else {
		return 501;
	}

	return $WSP_Result;
}

        
  ?>     
         
</div></div> 
		 <!-- End Content -->
		 
		 <!-- Begin Footer -->
		 
		   
			    
	     <div><?php require("footer.php"); ?></div>
		 <!-- End Footer -->
		 
</div>
<!-- End Wrapper -->


</body>
</html>


Post Reply