How to use GET in PHP

Home > Search > How-to
  by

In PHP, information can be passed from Page 1 to Page 2 using GET or POST. For example, lets say you have a Click here hyperlink on www.example.com/index.php.

 


GET

First, the Click here hyperlink will need to be configured to pass data to page 2. 

<a href='page2.php?id=1'> Click here </a>

 

In this example, when clicking on the Click here hyperlink, you will be redirected to Page 2, and the URL will contain ?id=1. On page2.php, the following PHP can be used to GET the data from the URL.

<?php
   $id = $_GET['id'];
   echo $id;
?>	

 

1 will be displayed on the page.



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments