Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

How to generate a random string using javascript,ajax and php

How to generate a random string using character, numbers and symbols. generate randon string using javascript,ajax and php with character,symbols, numbers and with specific length of string also,can create lenght of string as required to generated a string - upworkidea.

Create a index.php and this code  and you can download the jquery here to include to work ajax function


   
 <html>
<head>
<title>Random string code Generator using javscript, ajax and php</title>

 <script src="/jquery-2.1.4.min.js"></script>
 
 <script type="text/javascript">
   

function getrandonstringcode() {
         var length = 8;
       $.ajax({    

     url: "string.php", 

     method: 'post',

     data: {type:'string_action',length: length},

     dataType: 'html',

     success: function(response){

       response=response.replace(/(\r\n|\n|\r)/gm,"");
         $('#p_code').val(response);
          

     }

     });

}

</script>

</head>
<body>
<h1>Generate Random String using characters,numbers and symbols</h1>
          <input class="form-control" type="text" id="p_code" name="p_code" value="" placeholder="RandomString"/>
          <button type="button" onclick="getrandonstringcode()"  class="btn btn-success">Generate</button>

</body>
</html>
 Create a string.php file and add this code



   
 <?php  
   
   //only character or number only 
      if($_POST['type'] == 'string_action'){

       
      $length         = $_POST['length'];
        $useLetters     =  true;
        $useNumbers     =  true;
        $useSymbols     =  false;
      
        $uppercase    = ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M'];
        $lowercase    = ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm'];
        $numbers      = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
        $symbols      = ['`', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '=', '+', '\\', '|', '/', '[', ']', '{', '}', '"', "'", ';', ':', '<', '>', ',', '.', '?'];

        $characters   = [];
        $coupon = '';

        if ($useLetters) {
            if ($useMixedCase) {
                $characters = array_merge($characters, $lowercase, $uppercase);
            } else {
                $characters = array_merge($characters, $uppercase);
            }
        }

        if ($useNumbers) {
            $characters = array_merge($characters, $numbers);
        }

        if ($useSymbols) {
            $characters = array_merge($characters, $symbols);
        }
 
            for ($i = 0; $i < $length; $i++) {
                $randString .= $characters[mt_rand(0, count($characters) - 1)];
            }
     
     //print coupon and exit go to back to the index file  
       echo $randString;
     exit(0);

   

  }

?>  
and download jquery and include into the file



   <script src="/jquery-2.1.4.min.js"></script>
 

Generate coupon code and call ajax in codeigniter

Generate coupon code and call ajax in codeigniter


Its easy to call ajax in codeigniter and coupon code generate in codeigniter, onclick event to call ajax in javascript, create a randon coupon code of with length of code.


PHP interview question and answers

TOP PHP interview question and answers  here are which is asked in many organization/companies.

What is PHP?

PHP is a web language based on scripts that allow developers to dynamically create generated web pages, It is an open source server-side scripting language which is widely used for web development.

2) What do the initials of PHP stand for?

PHP means PHP: Hypertext Preprocessor.

2) What is PEAR in PHP?

PEAR stands for PHP Extension and Application Repository. PEAR is a framework and repository for reusable PHP components. It contains all types of PHP code snippets and libraries.

3) What is the use of a final class and a final method in php?

'final' method is introduced in PHP5,while Final class means that this class cannot be extended(not use in another class) and a final method cannot be overridden.

4)List of the Content Management Systems (CMS) in PHP?

WordPress
Joomla
Magento
Drupal and many more...

5) List of the popular frameworks in PHP?

CodeIgniter
Laravel
CakePHP
Yii 2
Symfony
Zend Framework and many more...