Tuesday, March 1, 2011

How to generate a unique id for different visitors with PHP?

The value will be used as:

from INTEGER UNSIGNED NOT NULL

which defines different visitors that haven't login.

How to properly generate that number with PHP?

EDIT:

If using database as follows:

create table user_visits(
    id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
    primary key(id)
);

How to insert a new record into it?

From stackoverflow
  • Use the id:

    INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT
    
    Shore : That's from database.How to do that from PHP?
    soulmerge : You posted the database field to insert to, so I thought you want to store them in the database. INSERT and select the inserted id with mysql_insert_id().
    Shore : OK,I've declined to use database now.But how to insert a new record into it?
    soulmerge : `INSERT INTO user_visits (id) VALUES (NULL);`
  • You can insert a value in a database each time with an auto_increment column.

    You can also use the php function uniqid().

  • http://www.php.net/manual/en/function.uniqid.php

    soulmerge : uniqid() returns a string

0 comments:

Post a Comment