Jump to content

2 Things, How to create a random, unique, customer number using php


random1234

Recommended Posts

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!
Link to comment
Share on other sites

Guest footballkid4
1)
[code]<?php
session_id();
?>[/code]
Should be unique for each visitor

2) file_get_contents(), file(), fopen(), fread(), fwrite(), fclose()
Link to comment
Share on other sites

[!--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]<?php
session_id();
?>[/code]
Should be unique for each visitor

2) 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

Link to comment
Share on other sites

[!--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..
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.