locations within a file

gesf

New member
Not sure about what you really want, but... here goes a lil' idea:
Code:
<?php

if (isset($_GET['something'])){

   if($_GET['something'] == 'about'){
      header('Location: http://www.site.com/about.php');
   }
   elseif($_GET['something'] == 'contact'){
      header('Location: http://www.site.com/contact.php');
   }
   elseif($_GET['something'] == 'links'){
      header('Location: http://www.site.com/links.php');
   }
   else{
      header('Location: http://www.site.com/error404.php');
   }

}

?>
This way you can pass to the file where this code is in, something like:

Example: index.php?something=contact
It will redirect to the proper location!
 
This is very, very simple PHP. You should start by reading the Introductory Tutorial and then starting reading the manual from the beginning. It may be helpful for you to purchase or borrow a good PHP book.
 
Here is how i include files, based on $_GET:


Code:
<?php
function inclusion($dir = './', $suffix = '.php', $defaultside = 'mainpage' , $includeparameter = 'i')
{


$ex = array('.', '..'); //strip files

if (is_dir($dir) && $dh = opendir($dir)) 
{ 
 
while (($file = readdir($dh))) 
{ 

 if(is_file($file) && (!in_array($file, $ex)))
 {

  $allowed_files[] = $file;


 }
     
}
 
} 
  closedir($dh); 




$include = $_GET[$includeparameter];
$include = str_replace(array('..', '//', 'ftp'), array('', '', ''), $include); 
$include = strtolower($include);

if(in_array($include . $suffix, $allowed_files))
{

include($include . $suffix);

}
else
{

if($_GET[$includeparameter]) {


 if($_SERVER['HTTP_REFERER'])
 {

  echo '<div>Link doesn't exist.</div>';

 }
 else
 {

  echo 'Sorry, page doesn't exist, go back to <a href="http://' . $_SERVER['HTTP_HOST'] . '">mainpage</a>';

 }

}
 else
{

 include($defaultside . $suffix);


}


}


}//end function

?>


If I want the page to take "base" in .inc-files under the directory "./include", where default.inc is the default page, and use $_GET['include'] instead of $_GET, I use this:

Code:
<?php
inclusion('./include', '.inc', 'default.inc', 'include');
?>
Otherwise, just
Code:
<?php inclusion(); ?>
 
Back
Top