Skip to content

Instantly share code, notes, and snippets.

@devinsays
Created November 24, 2018 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devinsays/22524499c8441f670b58284d9de10046 to your computer and use it in GitHub Desktop.
Save devinsays/22524499c8441f670b58284d9de10046 to your computer and use it in GitHub Desktop.
Sample Query String Appending
<?php
function devinsays_append_query_strings( $url ) {
error_log('inital url');
error_log($url);
// If no cookie set, return.
if ( ! isset( $_COOKIE['affwp_ref'] ) ) {
return $url;
}
// Get affiliate reference, and create query string.
$ref = $_COOKIE['affwp_ref'];
$query = "afftrack=$ref&subid=$ref&u1=$ref&sub-id=$ref";
// Modify the URL by appending the new query strings.
$modifiedUrl = $url;
$parsedUrl = parse_url($url);
error_log( print_r($parsedUrl, true ));
$separator = isset($parsedUrl['query']) ? '&' : '?';
$modifiedUrl .= $separator . $query;
error_log('modified url');
error_log($modifiedUrl);
return $modifiedUrl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment