Handy PHP thing I can\'t come up with a title for; display different data depending on where user comes from, sort of


/ Published in: PHP
Save to your folder(s)

If user enters city.php from footer.php, page will return certain string. If user enters independently, solution lets user see predefined string (in this case, 'your city').


Copy this code and paste it in your HTML
  1. footer.php:
  2.  
  3. <ul>
  4. <li><a href="city.php?city=<?php echo urlencode("Blerg County"); ?>&state=<?php echo urlencode("Massachusetts"); ?>">Blerg County</a></li>
  5. </ul>
  6.  
  7. city.php:
  8.  
  9. <?php echo urldecode($_GET['city']); ?>
  10. and
  11. <?php echo urldecode($_GET['state']); ?>
  12.  
  13. solution:
  14.  
  15. echo isset($_GET['city']) ? htmlentities($_GET['city']) : 'your city';

Report this snippet


Comments


You need to login to view comments.