random1234 Posted April 4, 2006 Share Posted April 4, 2006 Hey guys.I need some help with how to create a unique customer number for an online shopping website. The idea being that before you start shopping, you are issued with a unique number which identifies you as a customer, it is then written to a file and stored with the intention that next time you log on to the website, you can start ordering right away (by entering the number issued to you).Problem is, i don't know how to do that, or write to an actual file, so help with all that would be greatly appriciated. Oh, and i tried to read some Tutorials on how to write to files.....but they confused me a tad.Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/6544-2-things-how-to-create-a-random-unique-customer-number-using-php/ Share on other sites More sharing options...
Guest footballkid4 Posted April 4, 2006 Share Posted April 4, 2006 1) [code]<?phpsession_id();?>[/code]Should be unique for each visitor2) file_get_contents(), file(), fopen(), fread(), fwrite(), fclose() Quote Link to comment https://forums.phpfreaks.com/topic/6544-2-things-how-to-create-a-random-unique-customer-number-using-php/#findComment-23750 Share on other sites More sharing options...
random1234 Posted April 4, 2006 Author Share Posted April 4, 2006 [!--quoteo(post=361497:date=Apr 4 2006, 04:44 PM:name=footballkid4)--][div class=\'quotetop\']QUOTE(footballkid4 @ Apr 4 2006, 04:44 PM) [snapback]361497[/snapback][/div][div class=\'quotemain\'][!--quotec--]1) [code]<?phpsession_id();?>[/code]Should be unique for each visitor2) file_get_contents(), file(), fopen(), fread(), fwrite(), fclose()[/quote]Thank you for your quick response, but could you tell me how i can echo each vistors id so that they can see it on-screen and then write that to a file?Sorry for the simplistic question, but i'm really rather new to this. PHP is my first language ^^Thanks Quote Link to comment https://forums.phpfreaks.com/topic/6544-2-things-how-to-create-a-random-unique-customer-number-using-php/#findComment-23752 Share on other sites More sharing options...
Seamless Posted April 4, 2006 Share Posted April 4, 2006 [!--quoteo(post=361500:date=Apr 4 2006, 02:11 AM:name=Enter Display Name Here)--][div class=\'quotetop\']QUOTE(Enter Display Name Here @ Apr 4 2006, 02:11 AM) [snapback]361500[/snapback][/div][div class=\'quotemain\'][!--quotec--]Thank you for your quick response, but could you tell me how i can echo each vistors id so that they can see it on-screen and then write that to a file?Sorry for the simplistic question, but i'm really rather new to this. PHP is my first language ^^Thanks[/quote]I'm not an expert, but i think it would probably be something like this...[code]<?$unique_id = session_id();echo $unique_id;?>[/code]Seamless.. Quote Link to comment https://forums.phpfreaks.com/topic/6544-2-things-how-to-create-a-random-unique-customer-number-using-php/#findComment-23784 Share on other sites More sharing options...
kenrbnsn Posted April 4, 2006 Share Posted April 4, 2006 You REALLY want to use a database here. You would define the customerID field and make it unique. To generate it either you could use the auto-increment feature of most databases or generate a random number that is large enough to accommodate all the customers you anticpate getting. If you use a random number, after you generate it, try to insert the record using the number. If the insert succeeds, that is the customer number, if not generate another and try again. Put this generate/try into a "while" loop.Ken Quote Link to comment https://forums.phpfreaks.com/topic/6544-2-things-how-to-create-a-random-unique-customer-number-using-php/#findComment-23790 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.