hyperlink - How to link to the current PHP file -
i writing php file don't know best way create link while link in same file different id. mean have file named test.php
, contains like:
if ($id == "") { echo "<a href='".$_server['php_self']."?id=test'>try test page</a>"; } else if ($id == "test") { echo "here testing content various information!"; }
i want know better more secure code: $_server['php_self']?id=test
or test.php?id=test
.
i know serves same purpose now, if change file name $_server['php_self']?id=test
seems better because still point same file.
but know sure safer.
you should not printing $_server['php_self']
; it's security vulnerability (there's example here: how identify requested page in php).
if you're trying link same page, query parameters (?
) or anchors (#
) can link directly them, @kingkero suggests.
<!-- code snippet runs iframe http://stacksnippets.net/js, that's root of links you'll see if click "run". --> <a href="">link current page</a><br /> <a href="?id=test">add query param current page</a><br /> <a href="#anchor">add anchor tag current page</a>
links don't begin /
or protocol (like http://
) relative current document's location. links begin /
relative domain root. behavior laid out w3c.
broadly speaking, you're right, should avoid hard coding things filename file. should not need use data in $_server
construct links.
Comments
Post a Comment