Tuesday 9 March 2021

Php: Access query parameters

Using $_GET array, you can access the query parameters.

 

Syntax

$_GET['query_parameter_name']

 

Above statement access the value associated with query parameters. Let’s create an application to demonstrate this.

 

Step 1: Create welcome.php file under apache DocumentRoot location. In my case, I configured it to the location /usr/local/var/www.

 

welcome.php

<?php 
    $my_name = $_GET['name'];
    $my_age = $_GET['age'];

    echo "Hello $my_name, you are $my_age years old";
?>

 

Step 2: Restart httpd server by executing below command.

apachectl restart

 

Step 3: Open the url ‘http://localhost:8080/welcome.php?name=krishna&age=31’ in browser, you will see welcome message with user name and age.

 


 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment