Posted By

stephcode on 02/17/11


Tagged

php String htmlentities


Versions (?)

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
 

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').

  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  

You need to login to post a comment.