jarvis Posted June 22, 2011 Share Posted June 22, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/240085-google-analytics-_request-issue/ Share on other sites More sharing options...
requinix Posted June 22, 2011 Share Posted June 22, 2011 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); Quote Link to comment https://forums.phpfreaks.com/topic/240085-google-analytics-_request-issue/#findComment-1233253 Share on other sites More sharing options...
jarvis Posted June 22, 2011 Author Share Posted June 22, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/240085-google-analytics-_request-issue/#findComment-1233269 Share on other sites More sharing options...
jarvis Posted June 22, 2011 Author Share Posted June 22, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/240085-google-analytics-_request-issue/#findComment-1233349 Share on other sites More sharing options...
requinix Posted June 22, 2011 Share Posted June 22, 2011 Replace everything in the third block of code you posted. Quote Link to comment https://forums.phpfreaks.com/topic/240085-google-analytics-_request-issue/#findComment-1233533 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.