Page 1 of 1

fixed number of Tracking ID

Posted: Wed Oct 26, 2011 4:10 am
by taydu
Script URL:
Version of script:
Hosting company:
URL of phpinfo.php:
URL of session_test.php:
What terms did you try when SEARCHING for a solution:

Write your message below:
I notice that the tracking ID doesn't have the same number of varchar all the time sometime only 8 (abc-1de-481d) , sometime 10 (eud-38n-827s) and some time 9 (81n-s83-92n).

Is there a way to modify it so it always have 10 in any unique tracking id (xyz-yxz-yzzx)

Thanks

Re: fixed number of Tracking ID

Posted: Wed Oct 26, 2011 3:19 pm
by Klemen
The tracking ID should be XXX-XXX-XXXX all the time. I just ran the code through 1,000,000 iterations and it didn't generate a single error.

Did you do a clean install or updated Hesk to version 2.3 (if yes, from what version)? Did you have 2.3 beta installed?

Re: fixed number of Tracking ID

Posted: Thu Oct 27, 2011 4:37 pm
by taydu
I was a fresh install of 2.3. I will do fresh install and try it again see how that goes and will report back

Re: fixed number of Tracking ID

Posted: Fri Oct 28, 2011 4:52 am
by taydu
I did a fresh install and create 4 tickets and it seem to be working correctly. I did modify the common.inc.php a bit to suite for my use, i don't know if it could cause the problem. But with the code below out of 5 tickets created each of it will have different tracking ID length. Please take a look at the modify code and let me know if i did something wrong. BTW how can i run the code million time to make sure there no error. Sorry i'm not a coder so I don't it but would like to find out so i can use it to test in the future.

Thanks

Code: Select all

/* Ticket ID can be of these chars */
	$useChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';

    /* Generate the ID */
    $trackingID  = '';
    $trackingID .= $useChars[mt_rand(0,36)];
    $trackingID .= $useChars[mt_rand(0,36)];
    $trackingID .= $useChars[mt_rand(0,36)];
	$trackingID .= '-';
    $trackingID .= $useChars[mt_rand(0,36)];
    $trackingID .= $useChars[mt_rand(0,36)];
	$trackingID .= $useChars[mt_rand(0,36)];  
    $trackingID .= '-';	
    $trackingID .= $useChars[mt_rand(27,36)];
    $trackingID .= $useChars[mt_rand(27,36)];
    $trackingID .= $useChars[mt_rand(27,36)];
    $trackingID .= $useChars[mt_rand(27,36)];

	/* Check for duplicate Tracking ID. Small chance, but on some servers... */
	$sql = "SELECT `id` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` WHERE `trackid` = '".hesk_dbEscape($trackingID)."' LIMIT 1";
	$res = hesk_dbQuery($sql);

	if (hesk_dbNumRows($res) != 0)
	{
		/* Tracking ID not unique, let's try another way */
		$trackingID  = $useChars[mt_rand(0,36)];
		$trackingID .= $useChars[mt_rand(0,36)];
		$trackingID .= $useChars[mt_rand(0,36)];
		$trackingID .= $useChars[mt_rand(0,36)];
		$trackingID .= $useChars[mt_rand(0,36)];
		$trackingID .= substr(microtime(), -5);

Re: fixed number of Tracking ID

Posted: Fri Oct 28, 2011 2:58 pm
by Klemen
You better mention that you modified the ID generating code next time, you got me worried there :wink:

The problem in your code is number 36 in mt_rand - the $useChars string only has 30 chars (indexed from 0 to 29 by PHP) so the maximum number you can use in mt_rand in 29.

Change all instances of "36" to "29" and it should work.