Stefan83 Posted January 9, 2014 Share Posted January 9, 2014 HI I'm building a splash page that mobile users are redirected to when they visit a page on my website. from=(Original URI) is added the splash page's URL. There is a link at the bottom of the splash page which gets the value of the 'from' query to allow the user to click back to the orginal page.I'm trying to build a URL for this link with the following script so '?full=1' query string is appended to the end of the URL. Here's the code: <?php $qstring = array('full'=>'1' ); ?> <a href="<?php bloginfo('url'); echo htmlspecialchars($_GET["from"]); ?>?<?php echo http_build_query($qstring) . "\n"; ?>">Continue to Website</a> - get the current URL of a Wordpress site (eg http:www.domain.com)- echo the value of 'from' query (eg from=orginalpage)- and append the full=1The problem is if there is a query string already in the from URI from original page , I get an unwanted duplicate '?' in the URL. So if the original URL is http://www.domain.com/orginalpage/?test=1would redirect tohttp://www.domain.com/splashpage/?from=orginalpage/?test=1So the link looks likehttp://www.domain.com/orginalpage/?test=1?full=1How do I stop the duplicate '?' and replace with '&'?Thanks Link to comment https://forums.phpfreaks.com/topic/285237-issue-with-duplicate-in-query-string/ Share on other sites More sharing options...
Ch0cu3r Posted January 9, 2014 Share Posted January 9, 2014 You could try <?php // get the query string and parse into an array parse_str($_SERVER['QUERY_STRING'], $queryStringArray); // add full to array $queryStringArray['full'] = 1; // rebuild the query string $queryString = '?' . http_build_query($queryStringArray); ?> <a href="<?php bloginfo('url'); echo $queryString; ?>">Continue to Website</a> Link to comment https://forums.phpfreaks.com/topic/285237-issue-with-duplicate-in-query-string/#findComment-1464583 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.