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
https://forums.phpfreaks.com/topic/268367-unique-id/
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
https://forums.phpfreaks.com/topic/268367-unique-id/#findComment-1377918
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
https://forums.phpfreaks.com/topic/268367-unique-id/#findComment-1377929
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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