TESTING FOR A VARIABLE PASSED AT THE END OF A URL - Sep 30th, 2013


I needed to display some specific text on my products_page.php based on the value that was passed at the end of a URL
when a user clicked a link to get to that page. In my case the link that were passed looked like this, with numbers at
the end:

products_page.php?product=1
products_page.php?product = 2

but the URL could also have a text value at the end:

products_page.php?product=“product1"

Jason Sauchuk from Interactive Tools suggested defining a variable ($var1) like this:

<?php $var1=$_REQUEST['product']; ?>

With the variable defined, I could use if statements to produce the desired text.

<?php if ($var1 == 1):?> Text for value “1"
<?php elseif ($var1 == 2):?>Text for value “2"
<?php elseif ($var1 == “product1"):?>Text for value “product1"
<?php endif ?>






The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service