0

I have:

$token  = sha1(uniqid(mt_rand(), true));

Then I'll insert it into the database using unhex('$token'). How do I select this value?

I've tried:

SELECT token FROM `name` WHERE `id` = 1 LIMIT 1

If I echo it in it'll show as 0b7GÞ÷:‹xcÅ•½JAjdäáæ rather than something like 5dc012f007b7c4db7b9e076138fdd92fa1039530

What am I doing wrong?

2
  • "What am I doing wrong?" - how about: you are using UNHEX in the first place? I mean, what for do you do that? And if you really think this is necessary - why haven't you read in the manual about what the "inverse" function to UNHEX is? Commented Mar 17, 2013 at 0:36
  • @CBroe stackoverflow.com/questions/614476/… Commented Mar 17, 2013 at 0:39

1 Answer 1

1

I don't think you need to store it with UNHEX, but you can SELECT HEX(token) to get back the original value.

Sign up to request clarification or add additional context in comments.

1 Comment

I figured out moments ago I had to do "HEX(token) as token", leaving out the as token was causing an undefined index error. Thanks. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.