Ticket System in PHP - #2 Generating Tickets


This tutorial is a continuation from my previous tutorial in which I covered the database design and HTML password reset form scripting for this password reset ticket system.

Part Two - Fake Data:

Before we can even think of making a password reset ticket system, we need to create a fake user to which we can reset their password. This series isn't on how to make a register or login form(s) and so I will simply say, go to your PHPMyAdmin, select your database, then select your 'customers' table, then go to 'Insert' and enter some fake information. I have set my fake information to: ID - blank/Na/auto increment/1 Username - Yorkiebar Password - yui Email - example@gmail.com

Generate Random String Function:

Another short but required script or function we need for this system is a way to generate some random ticket text. This text will be used in order for the user to enter their ticket which will allow the require information be gathered therefore allowing them to reset their password via the HTML form we created in the previous tutorial, part one. This function will be named 'generateRandom'...
  1. function generateRandom() {
  3. }
The first thing we want to do within this new 'generateRandom' function is to set the acceptable characters for our ticket system. This will be any a-z character of lower and upper case for us...
  1. $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
The next thing we want to do is to create an empty variable which will hold our random text as it is being generated...
  1. $randomString = '';
Now we want to create a for loop. This loop will go from zero (0) to our ticket length (eight (8) in our case). Each time it loops, it is going to add a character from our 'characters' string object variable that holds all of our acceptable characters for our ticket and add it to our ticket variable 'randomString'...
  1. for ($i = 0; $i < 20; $i++) {
  2. $randomString .= $characters[rand(0, strlen($characters) - 1)];
  3. }
Finally we want our function to return the randomly generated string, this will be used as a new ticket later on...
  1. return $randomString;


Add new comment