Simple PHP Coupon Code Generator


Coupon Code Generator is a PHP script that allows you to create any number of random coupon codes. The generated coupon codes can contain a different set of characters and have different character lengths, option to add your own prefix and suffix. All generated coupon codes generated will be different, which makes it useful to provide discount coupon codes.

Recently, I was working on one of the the projects which needed coupon codes to be generated. So, I made a customizable interface to generate coupon codes.


Simple and Clean Interface


  1. Support to add prefix- and -suffix
  2. Support to add custom coupon mask
  3. Support to customize only numbers, only alphabets, only symbols or all
  4. Support to generate coupons N lengths (N- any number)
  5. Generate N number of coupons
  6. Option to export codes to excel sheet
  7. Simple and clean interface
  8. Ability to add the PHP class file to your own project
  9. Well documented with comments

Source Code and Project file on Github

  • Nirav Shah


    Could you guide if one had to save the coupons generated into a Mysql database how would one do the same. I am not well versed with this. would appreciate your help.

    • Hi Nirav,
      If you have worked on PHP before, its pretty simple.
      Use “generate_coupons” function from file. The result just use a loop and insert into your table database.

      • Rasa Msia

        if say want to generate x number of random coupon codes?

        will it be unique?

  • Rytis St.

    Parse error: syntax error, unexpected ‘[‘ in codes/ on line 21