PHPFAN10 Posted January 21, 2011 Share Posted January 21, 2011 Hi, I have a sign up form that generates a activation key and emails it to user and they cannot login until account has been activated etc. My problem is i am not sure how to in php generate a new activation key if the generated one has already been used. I know how to do the MySQL query to check if activation key already exists but not sure how to basically tell PHP that if the activation key already exists in DB then generate a new key until one is found that does not already exist. I gather i may need a loop but not sure. Could someone please help ? Like i say i know how to do the MySQL query just need some sample code to know how to do what i asked above. Thanks for anyhelp; Much Appreciated Quote Link to comment https://forums.phpfreaks.com/topic/225172-if-key-exists-regenerate-a-new-key/ Share on other sites More sharing options...
PHPFAN10 Posted January 21, 2011 Author Share Posted January 21, 2011 I was also meant to say i have a function that generates an activation key so don't need to know that either. Quote Link to comment https://forums.phpfreaks.com/topic/225172-if-key-exists-regenerate-a-new-key/#findComment-1162927 Share on other sites More sharing options...
PFMaBiSmAd Posted January 21, 2011 Share Posted January 21, 2011 You would need to query the database table to find out if the newly generated key is already present or not and loop until you generate a key that is not already in the table. You would also probably want to use a counter to limit the number of attempts to a reasonable number in case your code contains an error or you use up all the available key values for the key length you have picked. Quote Link to comment https://forums.phpfreaks.com/topic/225172-if-key-exists-regenerate-a-new-key/#findComment-1162951 Share on other sites More sharing options...
PHPFAN10 Posted January 21, 2011 Author Share Posted January 21, 2011 Thanks for the reply will try and figure the code out by reading your reply. Quote Link to comment https://forums.phpfreaks.com/topic/225172-if-key-exists-regenerate-a-new-key/#findComment-1163036 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.