Posted By

nerdfiles on 06/22/09


Tagged

url php include page parameter


Versions (?)

URL Parameter to Page Include


 / Published in: PHP
 

Combine with an .htaccess script to transpose URLs. Or simply have PHP parse "DOMAIN.com/var/" strings to URL parameters (that is, page=var). Search for "page title" variable in the page after the header() function.

  1. <?php
  2. header("Content-type: text/html;charset=utf-8");
  3. if(!isset($description))
  4. {
  5. $description = 'Default description for your site';
  6. }
  7.  
  8. if(!isset($title))
  9. {
  10. $title = 'Default page title for your site';
  11. }
  12.  
  13. ?>
  14. <html>
  15. <head>
  16. <title><?php echo $title; ?></title>
  17. </head>
  18. <body>
  19. <?php
  20. if (isset($_GET['page']) && $_GET['page'] != "") {
  21. $page = $_GET['page'];
  22. if (file_exists('sections/'.$page.'.php')) {
  23. @include ('sections/'.$page.'.php');
  24. } elseif (!file_exists('sections/'.$page.'.php')) {
  25. echo '404 error.'; //A quick and simple means to produce a 404 page through template.
  26. }
  27. } else {
  28. @include ('sections/landing.php');
  29. }
  30. ?>
  31. </body>
  32. </html>

Report this snippet  

You need to login to post a comment.