For example I have a URL like this one:
index.php?country=Canada
If it is just index.php that means that the default country is USA. People can switch between countries by checking or unchecking a checkbox.
But people can sort their results via GET variables:
<a href="<?php $_SERVER["REQUEST_URI"] ?>&sort=state">State</a>
<a href="<?php $_SERVER["REQUEST_URI"] ?>&sort=surname">Surname</a>
<a href="<?php $_SERVER["REQUEST_URI"] ?>&sort=name">Name</a>
But if I use $_SERVER["REQUEST_URI"] then it will always just keep adding new values to my URL array (query string). It works if it is just index.php then I can make it like this:
<a href="<?php $_SERVER["PHP_SELF"] ?>?sort=state">State</a>
<a href="<?php $_SERVER["PHP_SELF"] ?>?sort=surname">Surname</a>
<a href="<?php $_SERVER["PHP_SELF"] ?>?sort=name">Name</a>
I know that after index.php it will always be a question mark ? first.
But what when visitors want to keep index.php?country=Canada and just switch between sort=state, sort=surname and sort=name. Then I need to know if a question mark is already in the URL, when to add & mark. I'm not sure how to solve this problem.