Jump to content

Hash User ID Retrieve


JohnOP

Recommended Posts

When a user logs in to my site i hash there user id so when they go to profile etc it looks like

 

profile.php?id=47685746378264853

 

rather than there unique id, the trouble i am having is when on there profile i want to query the database to grab that users profile information, i normally do it by getting the id then use it in the query WHERE clause, but the id is hashed so no match will be found with that id, any way around that or im i missing something stupid lol?

Link to comment
https://forums.phpfreaks.com/topic/243299-hash-user-id-retrieve/
Share on other sites

Add another column in the table for the hashed value of the id. Since you already have queries for grabbing information by ID I wouldn't create all new queries to do searched by hash since you will likely still need the ones that use ID. That would require you to have a lot of duplicate queries.

 

Instead, I would suggest you modify your existing queries to use id OR hash. that wayt he queries will work regardless of what value you pass. And, you wouldn't have to worry about getting the wrong values since there would be no chance of one user's ID matching another user's hash.

 

Example

SELECT *
FROM user_table
WHERE active = 1
    AND (id = '$value' OR hash = '$value')

 

Just use "(id = '$value' OR hash = '$value')" in place of where you are using the id comparison now

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.