Jump to content

unique ID


the-botman

Recommended Posts

hey guys seems i have a small problem, see this is how i add a unique Id but it ends up to long

function GetGuid() {
$Date = date('Y')."-".date('m')."-".date('d');
$Time = date('H')."-".date('i')."-".date('s');
$Str = "$Date-$Time-";
$Guid = str_replace('-', '', uniqid($Str, TRUE));
$Guid = str_replace('.', '', $Guid);
return $Guid;
}

is there a way to make it little shorter? and will it be a safe option.

thanks in advance

zainul

Link to comment
Share on other sites

What are you trying to accomplish? What is too long?

 

$Guid = uniqid(date('YmdHis'), true));
return strtr($Guid, '.', ' ');

 

There. I made it shorter! :P

 

 

I think the string that uniqid() returns actually contains the input string at the beginning so you could remove that if you want:

 

$Guid = substr($Guid, 14);

 

It all depends on what you are trying to do with it.

Link to comment
Share on other sites

this was the only way i knew how to set unique Gbk_Id`s for each entry, i found it to be to long but never really tried any other way untill i started upgrading my guestbook. so when ever i am adding an entry i do it like..

	$Name = GetPost('Name');
$Message = GetPost('Message');

	if ($Name != "" && $Message != "") {
		$Entry_ID = GetGuid();
		$Entry_Date = date('Y')."/".date('m')."/".date('d');
		$Entry_Time = date('H').":".date('i').":".date('s');
 		$DbRes = MySqlCmd("INSERT INTO page_guestbook VALUES ('$Entry_ID','$Entry_Date','$Entry_Time','$Name','$Message')");

and the getguid is like this

function GetGuid() {
$Date = date('Y')."-".date('m')."-".date('d');
$Time = date('H')."-".date('i')."-".date('s');
$Str = "$Date-$Time-";
$Guid = str_replace('-', '', uniqid($Str, TRUE));
$Guid = str_replace('.', '', $Guid);
return $Guid;
}

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.