Created
November 24, 2018 18:25
-
-
Save devinsays/22524499c8441f670b58284d9de10046 to your computer and use it in GitHub Desktop.
Sample Query String Appending
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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