Page 204 - CITS - Computer Software Application -TT
P. 204

COMPUTER SOFTWARE APPLICATION - CITS




           Check if Cookies are Enabled
           The following example creates a small script that checks whether cookies are enabled. First, try to create a test
           cookie with the setcookie() function, then count the $_COOKIE array variable:
           Example:




























            Captcha text generation

           CAPTCHA Text Generation in PHP
           Introduction:
           CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart) is a security mechanism
           designed to differentiate between human users and automated bots. Text-based CAPTCHAs involve generating
           and validating distorted text that users must interpret and enter correctly to prove they are human.
           Explanation:
           The  primary  purpose  of  a  text-based  CAPTCHA  is  to  prevent  automated  scripts  from  submitting  forms  on
           websites, as bots often struggle to decipher and interpret distorted text. In PHP, CAPTCHAs can be implemented
           by generating a random text string, displaying it as an image, and validating the entered text against the stored
           value.
           Implementation:
           Let’s break down the steps to create a simple text-based CAPTCHA in PHP using the GD library:
           1  Generate a Random Text String:


















           In this example, we use the `md5` function with the current timestamp to create a random string and store it in the
           session variable ‘captcha.’





                                                           191

                             CITS : IT&ITES - Computer  Software Application - Lesson 47 - 62
   199   200   201   202   203   204   205   206   207   208   209