You can see dynamic URLs everywhere on the web with busy interactive sites. Variables and their values are passed from one page to another in this way. Or more precisely, a page served in PHP (a single file php script) can accept external input in the form of a dynamic URL such as http://www.asite.com/send.php?[email protected]&subject=hi&body=bye.
In the example above, when someone accesses this URL in browser, 3 variables and their values are successfully passed to the php script send.php. It then takes the input, does some basic processing and sends an email to [email protected] with hi as the subject and bye as the body message.
Therefore to pass variables and their values from one page to another, you can just make a static HTML link:
<a href="http://www.asite.com/send.php?[email protected]&subject=hi&body=bye.">send the email</a>
on the source page. After one clicking the link and navigating to the URL, the email is sent after send.php gets the 3 values.
Inside send.php we can access and use the values passed to it in the following way:
<?php $recipient = $_GET['recipient']; // Thatâ€™s it. Any variable value passed in URL can be accessible via array $_GET. $subject = $_GET['subject']; $body = $_GET['body']; mail($recipient, $subject, $body); // php mailing function ?>
Aside from $_GET, $_REQUEST can also be used to access these variables.