<?php 
  session_start();
    $_SESSION['addoncaptcha']='';
   // Generate captcha code
  $random_num    = md5(openssl_random_pseudo_bytes(10));
  $captcha_code  = substr($random_num, 0, 6);
  // Assign captcha in session
  $_SESSION['addoncaptcha'] = $captcha_code;
  // Create captcha image
  $layer = imagecreatetruecolor(130, 47);
  $captcha_bg = imagecolorallocate($layer, 266, 35, 130);
  imagefill($layer, 0, 0, $captcha_bg);
  $captcha_text_color = imagecolorallocate($layer, 255, 255, 255);
  imagestring($layer, 5, 40, 15, $captcha_code, $captcha_text_color);
  header("Content-type: image/jpeg");
  imagejpeg($layer);
?>