Page 281 - Computer Software Application TP - Volume 1
P. 281

COMPUTER SOFTWARE APPLICATION - CITS




                 $url = “http://localhost:8012/csa/querystring2.php?”.$query_string;         header(“Location: $url”);//
                    Redirect with query string

                                      exit(); // Stop further script execution


                 ?>
                       </body>
                                </html>
              3  Save the program in C:\Apache24\htdocs in a folder as querystring1.php extension

              4  Run the Apache services from windows services
              5  Open the browser and type the following address
                                     http://localhost/foldername/
              6  Click the php file to run  and verify the output

           II  Processing query string
                 1  Open the text editor
                 2  Write the following codes
                                 <html>
                                 <body>

                               <?php
                                   echo “Processing query string...<br/> “;
                  // Check if query string parameters exist
                 if(isset($_GET[‘name’]) && isset($_GET[‘age’]))
                 {

                          // Retrieve and sanitize the parameters
                         $name = htmlspecialchars($_GET[‘name’]);
                         $age = intval($_GET[‘age’]); // Convert age to integer
                         // Process the parameters
                         if($age >= 18)

                 {
                                        echo “$name is an adult.”;
                         }
                 else

                 {
                                        echo “$name is a minor.”;
                         }
                 }
                 else
                 {

                          // If parameters are not provided, display an error message
                         echo “Please provide name and age parameters.”;
                 }


                                                           266
                                CITS : IT & ITES - Computer Software Application - Exercise 54
   276   277   278   279   280   281   282   283   284   285   286