Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibraryManaging Website Forms

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Form Defeats Anti-malware Software

When a few form users are unable to submit your form or get warning messages in their browsers, but others can use the form with no problem, it may have to do with anti-malware software the user has installed on their computer.

A number of months ago, it happened to a website using Master Form V4.

The form was being submitted to another domain, which is likely what triggered the user's anti-malware software. (Master Form V4 can accept form submissions from any domain.)

The solution was simple and I'll disclose it in a moment.

If your form submits to a script on a domain other than where the form is located, anti-malware software may incorrectly alert the user to a security risk.

It most likely would depend on the settings the user has specified, but that's neither here nor there. The user thinks your form isn't working or it has malicious code.

You're innocent, of course. But the user doesn't know that. All they're focused on is your form not working and the message they're seeing.

The solution is to submit the form to a relay script located on the same domain as the form.

The form submits to the relay script and the relay script submits the form data to Master Form V4 at the other domain. It works a treat.

Here's the script. A customization note follows.

<?php
/* 
   Form Submission Relay
   Version 1.0
   December 23, 2013

   Will Bontrager Software LLC
   https://www.willmaster.com/
   Copyright 2013 Will Bontrager Software LLC

   This software is provided "AS IS," without 
   any warranty of any kind, without even any 
   implied warranty such as merchantability 
   or fitness for a particular purpose.
   Will Bontrager Software LLC grants 
   you a royalty free license to use this 
   software provided this notice appears 
   on all copies. 
*/

/* Customization */

$relayURL = 'http://www.example.com/cgi-bin/MasterFormV4.cgi';

/* End customization */


$relayMethod = substr( strtolower($_SERVER['REQUEST_METHOD']), 0, 1 );
if( $relayMethod == 'g' ) { GETaPage(); }
else { POSTaPage(); }
exit;

function POSTaPage()
{
   global $relayURL;
   $data = PrepareData();
   $options = cURLoptions();
   $options[CURLOPT_POST] = 1;
   $options[CURLOPT_POSTFIELDS] = $data;
   $info = array();
   $ch = curl_init($relayURL);
   curl_setopt_array($ch,$options);
   $content = curl_exec($ch);
   $err = curl_errno($ch);
   $errmsg = curl_error($ch) ;
   curl_close($ch);
   if( $err ) { echo "ERROR: $errmsg<hr>"; }
   echo $content;
} # function POSTaPage()


function GETaPage()
{
   global $relayURL;
   $data = PrepareData();
   $options = cURLoptions();
   $url = $relayURL . "?$data";
   $info = array();
   $ch = curl_init($url);
   curl_setopt_array($ch,$options);
   $content = curl_exec($ch);
   $err = curl_errno($ch);
   $errmsg = curl_error($ch) ;
   curl_close($ch);
   if( $err ) { echo "ERROR: $errmsg<hr>"; }
   echo $content;
} # function GETaPage()


function PrepareData()
{
   global $relayMethod;
   if( $relayMethod == 'g' ) { return URLencodeData($_GET); }
   else { return URLencodeData($_POST); }
} # function PrepareData()


function URLencodeData($ar)
{
   if( ! count($ar) ) { return ''; }
   $ta = array();
   foreach($ar as $k => $v)
   {
      if( is_array($ar[$k]) )
      {
         foreach( $ar[$k] as $kk => $vv )
         {
            if( is_array($ar[$k][$kk]) )
            {
               foreach( $ar[$k][$kk] as $kkk => $vvv )
               {
                  $ta[] = urlencode(stripslashes($k)) . '[' . urlencode(stripslashes($kk)) . '][' . urlencode(stripslashes($kkk)) . ']=' . urlencode(stripslashes($vvv));
               }
            }
            else { $ta[] = urlencode(stripslashes($k)) . '[' . urlencode(stripslashes($kk)) . ']=' . urlencode(stripslashes($vv)); }
         }
      }
      else { $ta[] = urlencode(stripslashes($k)) . '=' . urlencode(stripslashes($v)); }
   }
   return implode('&',$ta);
} # function URLencodeData()


function cURLoptions()
{
   $options = array(
      CURLOPT_RETURNTRANSFER => true,  // Return web page
      CURLOPT_HEADER         => false, // Don't return headers
      CURLOPT_CONNECTTIMEOUT => 120,   // Timeout on connect
      CURLOPT_TIMEOUT        => 120,   // Timeout on response
      CURLOPT_FOLLOWLOCATION => true,  // Follow redirects
      CURLOPT_USERAGENT      => $_SERVER['HTTP_USER_AGENT'],
      CURLOPT_VERBOSE        => false
   );
   if( ! empty($_SERVER['HTTP_REFERER']) )
   {
      $options[CURLOPT_REFERER] = $_SERVER['HTTP_REFERER'];
   }
   if( count($_COOKIE) )
   {
      $ta = array();
      foreach( $_COOKIE as $k => $v ) { $ta[] = "$k=$v"; }
      $options[CURLOPT_COOKIE] = implode('; ',$ta);
   }
   return $options;
} # cURLoptions()
?>

Customization note: The only customization is to specify the URL of the script to relay the form data to. The section is marked.

The script requires the PHP cURL library be installed. In my experience, most hosting companies have it preinstalled and ready to go for you.

The relay script works for Master Form V4 and should work for other scripts.

If you have a need for it, give it a try. Users' anti-malware software doesn't have to prevent your form from working.

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC