Jump to content

Recommended Posts

Hi,

 

Hope some one can help. We've a CMS which has the following code:

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
  require_once "E:/domains/a/domain.com/user/htdocs/cms/lib/viewer_functions.php";
?>
<?php
/*Code filters out unwanted variables from $_REQUEST and $_SERVER['QUERY_STRING'] so they don't interfer with automatic searching functions*/    
$filtered=array();
$filtered_query="";

//Filter
foreach($_REQUEST as $key=>$value){
    switch($key){
       //keys to filter out
     case "utm_medium":
     case "utm_source":
     case "utm_content":
     case "utm_campaign": 
         continue;
         break;
     default:
       $filtered[$key]=$value;
       $filtered_query.=$key."=".$value."&";
       break;
    }
}
  
$temp = $_REQUEST; //store $_REQUEST in a temporary variable  $temp_query = $_SERVER['QUERY_STRING'];

//set variables to filtered state
$_REQUEST=$filtered;
$_SERVER['QUERY_STRING']=$filtered_query;

/* **getRecords function must come AFTER this line** */
?>
<?php
  list($home_pageRecords, $home_pageMetaData) = getRecords(array(
    'tableName'   => 'home_page',
    'where'       => whereRecordNumberInUrl(1),
    'limit'       => '1',
'allowSearch' => '0',
  ));
  $home_pageRecord = @$home_pageRecords[0]; // get first record
?>

On the same page is an include to an enquiry form, the code for this is as follows:

  // process form
  if (@$_REQUEST['submitForm']) {

    // error checking
    $errorsAndAlerts = "";
$check = $_REQUEST['check'];
$randomNumber = $_REQUEST['randomNumber'];
    if (!@$_REQUEST['name'])                	{ $errorsAndAlerts = "Please add your name\n"; }
    if (!@$_REQUEST['email'])                   { $errorsAndAlerts = "Please add your email\n"; }
    else if(!isValidEmail(@$_REQUEST['email'])) { $errorsAndAlerts = "That email address is not valid\n"; }
    if (!@$_REQUEST['enquiry'])                 { $errorsAndAlerts = "Please add your enquiry\n"; }
if (!@$_REQUEST['randomNumber'])          	{ $errorsAndAlerts = "Please verify the number\n"; }

$textToConvert = $_REQUEST['enquiry'];
$convertedText = iconv("UTF-8", "ISO-8859-1", $textToConvert);

    // send email user
    if ((!$errorsAndAlerts) && ($randomNumber == $check)) {
      $to      = "[email protected]";	
      $subject = "Quick Contact";
  $email    = "[email protected]";

  $headers  = "MIME-Version: 1.0\r\n";
  $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
  $headers .= "From: $email \r\n";
  
  $body =  "<strong>Full name</strong>: ". $_REQUEST['name'] ."<br />";
  $body .= "<strong>Email</strong>: ".$_REQUEST['email'] ."<br />";
  $body .= "<strong>Enquiry</strong>: $convertedText<br /><br />";
  $body .= "The user who sent this message had the IP address <strong>".$_SERVER['REMOTE_ADDR']."</strong><br />";

  $message = $body;	  

      // send message
      $mailResult = @mail($to, $subject, $message, $headers);
      if (!$mailResult) { die("Mail Error: $php_errormsg"); }
  redirectBrowserToURL("http://www.domain.com/thanks.php");
      #$errorsAndAlerts = "Thanks!  We've sent your email.";
      $_REQUEST = array(); // clear form values

}

  }

Problem is, the code which checks & filters for Google Analytics:

<?php
/*Code filters out unwanted variables from $_REQUEST and $_SERVER['QUERY_STRING'] so they don't interfer with automatic searching functions*/    
$filtered=array();
$filtered_query="";

//Filter
foreach($_REQUEST as $key=>$value){
    switch($key){
       //keys to filter out
     case "utm_medium":
     case "utm_source":
     case "utm_content":
     case "utm_campaign": 
         continue;
         break;
     default:
       $filtered[$key]=$value;
       $filtered_query.=$key."=".$value."&";
       break;
    }
}
  
$temp = $_REQUEST; //store $_REQUEST in a temporary variable  $temp_query = $_SERVER['QUERY_STRING'];

//set variables to filtered state
$_REQUEST=$filtered;
$_SERVER['QUERY_STRING']=$filtered_query;

/* **getRecords function must come AFTER this line** */
?>

Seems to break the enquiry form. I'm guessing it's due to the $_REQUEST part of it. We need the filter in place because the CMS can't find a record if the URL has the UTM tagged on, filtering this out sorted the issue. Problem is, its now broken the enquiry form.

 

Is there anything I can do to resolve this?

 

TIA

 

jarvis

Link to comment
https://forums.phpfreaks.com/topic/240085-google-analytics-_request-issue/
Share on other sites

What does "broke" mean? Errors? Incorrect behavior? We can't see it running so we don't know.

 

Perhaps a better version of the filter would fix it?

foreach (array("utm_medium", "utm_source", "utm_content", "utm_campaign") as $key) {
unset($_REQUEST[$key]);
unset($_GET[$key]);
}
$_SERVER["QUERY_STRING"] = http_build_query($_GET);

Hi requinix

 

Sorry by broke it means if you try and submit the enquiry form, it would simply go to page cannot be found, it didn't even check to validate the form.

 

Is your suggested code to replace this:

<?php /*Code filters out unwanted variables from $_REQUEST and $_SERVER['QUERY_STRING'] so they don't interfer with automatic searching functions*/     $filtered=array(); $filtered_query="";  //Filter foreach($_REQUEST as $key=>$value){    switch($key){       //keys to filter out     case "utm_medium":     case "utm_source":     case "utm_content":     case "utm_campaign":          continue;         break;     default:

Thanks again

I've tried the above code. Although it doesn't show the error page, it now seems like the form doesn't submit at all or show any validation errors if you just click the submit button.

 

I simply replaced the existing filter code with the above, I assume that was right?

Thanks

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.