I'm building a web app and just working on the logout functionality (simple session unset / meta refresh/redirect code on logout.php)
Possible a simple question (though I've hunted around on Google to no avail), but for the logout button on the site, is there any benefit in using a form that submits to logout.php vs a button graphic with an a href that links to the same page?
Functionally, they both seem to work the same, but is there any potential securi开发者_Go百科ty issue etc?
Thanks heaps!
No, unless you need to actually post something to the login script, both methods will work fine.
A link might be easier to crawl by a search engine spider than a form but seeing as this is a logout button, that will not make a difference.
A link has the minor upside that you can easily bookmark it. I would go with a link.
Edit: Also check out @dqhendrick's comment about linking. It is probably not overly important for your context, but it's good to keep in mind.
There are two things that miiiight be relevant here:
- If it's a form and it POSTs instead of GETting, you will need to redirect to get around the usual browser back button + POST data unpleasantness. Of course you already mention redirecting, so this is probably not relevant.
- Since HTTP GET requests are supposed to be idempotent, "the right way" to do it should be with POST, which means a form. However, this kind of argument lacks practical justification. You should be just fine with links unless some ill-behaved and/or misconfigured browser addon decides to make life difficult for your users.
In essence, there should be no practical difference.
It may be useful to consider in addition to the other answers accessibility implications when making this decision. A button signals to a visual user or screenreader an abstract action is going to occur, something more than just navigation.
You wouldn't expect to open sign-out "in a new tab" like a link, for example. A button helps imply extra meaning.
精彩评论