I have on website a part which is at the moment hidden. I have also a few requests on query string ?visible=true
. How can i add this query string automatic to every url if in url is this querystring available ?visible=true? This is simple method where i enable hidden parts of website.
2 Answers
If i understand you correctly, you mean your page loads with various parameters and your wanting to have the next page load with any existing parameters as well as any that you want to add along with them.?
Example: somepage.html?visible=true&showmenu=5
Then you want to add "anotheropt=helloworld"
Example: somepage.html?visible=true&showmenu=5&anotheropt=helloworld
To do something like this, you have a few different options depending on what resources you have available...
Javascript / Client Side:
- Use a function to get all the parameters from the current url Something Like This
- Loop over all of them and build a new string with the ones you want to keep
- Add your own to the end of the string
Note the above link only retrieves them by name, you would want to simple do a split/explode type operation on the string and them perform your own logic to which items you want.
PHP / Server Side:
- Same deal, loop or something to get all of the current ones $_GET should do...
- Echo these into a hidden input box and append them to the end of new links..
Note you still need to filter your parameters to choose what to keep and what to ignore.
Further more, it would not be hard to write or find a function that will merge two arrays or perform a comparison.
OR
Is it as simple as this below??
var x = location.search;
var sl = "mypage.html" + x + "&someoption=helloworld"
OR THIS
<?php
if (isset($_GET['visible']) && $_GET['visible']=='true') {
echo "SHOW ME, i was a hidden element";
} else {
// NOTHING, VISIBLE IS NOT TRUE OR NOT SET...
}
?>
-
This isn't an answer, it should be a comment. – Barmar Oct 23 '14 at 07:27
-
Was having issues submitting, so had to type in short bursts.. hence edited as quickly as possible – Angry 84 Oct 23 '14 at 07:36
Your home page is accessed without ?visible=true
. So you have add it at-least once. When you make link, call some function for that:
<a href="<?php echo Link::url('about-us', true); ?>"></a>
class Link {
const BASE_URL = 'http://example.com';
public static function url($link, $visible = false) {
return self::BASE_URL."/".$link.(!empty($visible) ? '?visible=true' : '');
}
}

- 41,402
- 5
- 66
- 96