fixed number of Tracking ID

Helpdesk for my helpdesk software

Moderator: mkoch227

Post Reply
taydu
Posts: 4
Joined: Sun Oct 09, 2011 6:46 am

fixed number of Tracking ID

Post 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
Klemen
Site Admin
Posts: 10145
Joined: Fri Feb 11, 2005 4:04 pm

Re: fixed number of Tracking ID

Post 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?
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
taydu
Posts: 4
Joined: Sun Oct 09, 2011 6:46 am

Re: fixed number of Tracking ID

Post 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
taydu
Posts: 4
Joined: Sun Oct 09, 2011 6:46 am

Re: fixed number of Tracking ID

Post 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);
Klemen
Site Admin
Posts: 10145
Joined: Fri Feb 11, 2005 4:04 pm

Re: fixed number of Tracking ID

Post 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.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Post Reply