E
E
Extramezz2015-09-27 13:30:51
PHP
Extramezz, 2015-09-27 13:30:51

Link with a GET request?

Suppose the current page address is: http://site.ru/page.php?one=p1.
There is a link on the page, like: <a href="?two=p2">Тык</a>.
But if you follow it, the one parameter will be erased and the current url will become:
http://site.ru/page.php?two=p2.
Question: How to specify a link so that it eventually redirects:

  • WITH http://site.ru/page.php?one=p1ON http://site.ru/page.php?one=p1&two=p2.
  • And at the same time WITH http://site.ru/page.phpONhttp://site.ru/page.php?two=p2

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
IvanSenishin, 2015-09-27
@IvanSenishin

It is necessary to check the presence of a GET parameter in the current URL and, based on this, generate link parameters

$urlParams = '';
if (empty($_GET)) {
     $urlParams = '?two=p2';
} else {
     $urlParams = '&two=p2';
}
<a href="$urlParams">Тык</a>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question