获取符合条件的原始 URL referer

Get original URL referer with the condition

我需要通过联系表收集数据并跟踪客户推荐。我正在为表单创建一个标签,但只有在从包含 partner

的推荐转换时才需要填写它

我的代码

// Original Referrer 
function wpshore_set_session_values() 
{
    if (!session_id()) 
    {
        session_start();
    }

    if (!isset($_SESSION['OriginalRef'])) 
    {
        $_SESSION['OriginalRef'] = $_SERVER['HTTP_REFERER']; 
    }

    if (!isset($_SESSION['LandingPage'])) 
    {
        $_SESSION['LandingPage'] = $_SERVER["REQUEST_URI"]; 
    }
      

}
add_action('init', 'wpshore_set_session_values');

/// 
function getRefererPage3( $form_tag ){  

$partner = array (
  '/partner/',
);
$parts = parse_url($_SERVER['HTTP_REFERER'];
if (!empty($parts['path']) || in_array($parts['path'], $partner)){   //this row. I doubt how it should be
    if ( $form_tag['name'] == 'referer-page3' ) {   
    $form_tag['values'][] = $_SESSION['LandingPage'];
}
}
return $form_tag;
}

if ( !is_admin() ) {
add_filter( 'wpcf7_form_tag', 'getRefererPage3' );
}

我发现了我的问题。也许这个解决方案将来会对任何人有所帮助。

function getRefererPage3( $form_tag ){  
    if (strpos($_SESSION['LandingPage'], 'partner') !== false) { 
        if ( $form_tag['name'] == 'referer-page3 ) {    
        $form_tag['values'][] = $_SESSION['LandingPage'];
    }
    }
    return $form_tag;
    }
   if ( !is_admin() ) {
    add_filter( 'wpcf7_form_tag', 'getRefererPage3' );
    }