Jump to content

Recommended Posts

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=1


The 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=1

would redirect to

http://www.domain.com/splashpage/?from=orginalpage/?test=1

So the link looks like

http://www.domain.com/orginalpage/?test=1?full=1

How do I stop the duplicate '?' and replace with '&'?

Thanks
 

Edited by Stefan83
Link to comment
https://forums.phpfreaks.com/topic/285237-issue-with-duplicate-in-query-string/
Share on other sites

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>
Edited by Ch0cu3r
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.