If you click the link, nothing happens because the URL only contains the fragment identifier #
. Not even a GET
request will be issued.
You use this kind of link normally to jump to an element inside the page (e.g. <a href="#top">Top</a>
to jump to an element with ID top
). This is completely handled in the browser.
And if you only put the fragment identifier there, just nothing will happen. This is very often used if the link should execute some JavaScript and should actually not link to something else.
You are testing the $_POST
array at the server side. But this array only contains elements, if you initiate a POST
request by a form. That means you need to create a form with a submit button, e.g.:
<form action="" method="POST">
<input type="submit" name="logout" value="Exit Group" />
</form>
Here comes the name
attribute into play, which will be the key in the $_POST
array. But assigning this on a normal link will have no effect.
You could do it also with the link, but with a GET request this way:
<a id="exit" href="?logout=1">Exit Group</a>
<!-- ^-- parameter must be part of the URL, name has no effect -->
and
if(isset($_GET['logout'])){
//CODE TO BE EXECUTED
}
Note that you have to pass a parameter logout
it here.
It seems you have mixed up GET
and POST
requests. If you have a form, the name
s of the form elements will be transmitted as parameters to the server. That means given this form:
<form method="POST">
<input type="text" name="foo" value="" />
<input type="text" name="bar" value="" />
<input type="submit" name="send" value="Send" />
</form>
if the user clicks on the submit button, the $_POST
array at the server side will have the keys:
$_POST['foo']
$_POST['bar']
$_POST['send']
This does not work with links though. A click on a link will create a normal GET
request, and here, the parameters must be part of the URL, appended after a question mark ?
and separated by an ampersand &
:
<a href="somePage.php?foo=1&bar=1&andMore=0"> Link </a>
will result in
$_GET['foo']
$_GET['bar']
$_GET['andMore']
You probably should read about the HTTP protocol.