JohnOP Posted July 30, 2011 Share Posted July 30, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/243299-hash-user-id-retrieve/ Share on other sites More sharing options...
Psycho Posted July 30, 2011 Share Posted July 30, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/243299-hash-user-id-retrieve/#findComment-1249495 Share on other sites More sharing options...
JohnOP Posted July 30, 2011 Author Share Posted July 30, 2011 Yeah i though about that, guess ill do that thank you for your answer. Quote Link to comment https://forums.phpfreaks.com/topic/243299-hash-user-id-retrieve/#findComment-1249496 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.