Reputation: 139
I am at my first php project and I'm learning a lot.
In my project, i used to put in html id attribute values from my database, to make my work easier. For example:
<a id="nameOfMyTable_ID"> some link... </a>
<a id="idOfRow_idOfForeignKey_idOfCurrentUser"> .... </a>
It's that ok, or i'm doing it wrong ?.... I don't know for sure if that is a good practice. It's there any chance for vulnerability ?
I'm sorry, the qustion may sound stupid for some of you, but I really don't know if i'm doing wright.
Upvotes: 0
Views: 165
Reputation: 29675
I was going to put it as a comment but got a bit big:
The chances at vulnerabilities will depend on how you process those values before/after presenting them to the user (and I'm sure that you are applying fixes for them):
idOfRow_idOfForeignKey_idOfCurrentUser
with a value of 1_23_45, but I change it somehow to 1_34_78. What would happen then? Is the code ready for that or will I be updating somebody else's record?I don't know if the way IDs are displayed on the post can be considered as a good practice, personally I wouldn't do it that way, and even if I did, I'd follow some rules:
href
or in a data-
attribute.I tried to focus on the ones that would apply to the example in the question (although they'd apply to any project), and probably missing something.
Upvotes: 1
Reputation: 1388
Since you are passing the user's id into the id attribute of an <a>
tage, I'll assume you are trying to link to a page that needs the user's id. In this case, you would instead want to pass the user's id as a GET
parameter in the link.
Replace
<a id="idOfRow_idOfForeignKey_idOfCurrentUser">...</a>
With
<a href="myOtherPage.php?id=<?=$userID?>"> .... </a>
Note: I changed your variable from $idOfRow_idOfForeignKey_idOfCurrentUser
to $userID
to make it a little cleaner, but the idea is to simply pass the User's id to the next page using the href
attribute
Upvotes: 0