FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


URL Parameters PHP





FlyingYouri
Does anyone know how to use in a website URL Parameters? http://asite.com/index.php?page=apage that is what i will know. Is there any tutorial from? Or whatever?
Peterssidan
to get the value of page use $_GET["page"] in php.
erlendhg
This might be the thing you are looking for.

I use this code to include subpages in a main pages instead of using frames.

Code:
<?php

$dir = 'subpages'; //directory with files to include

$extensions = array('.php', '.html', '.htm', 'shtml', 'asp', 'aspx', 'cgi', 'pl', 'hts', 'txt');

if (isset($_REQUEST['page']) && !empty($_REQUEST['page'])) {
   $page = $_REQUEST['page'];
   $page = str_replace("../", "", $page); /* prevents getting information from parent directory */
   foreach ($extensions as $e) {
      if (file_exists($dir."/".$page.$e)) {
         $ext = $e;
         break;
      }
   }
 
   if (!isset($ext)) { //If no file was found
       if (file_exists($dir."/".$page."/")) { //...look for a folder,...
           if ($i_handle = opendir($dir."/".$page)) { //...and try to open the folder
               while (false !== ($i_file = readdir($i_handle)) && $i_file_pieces[0] != "index") {
                   if ($i_file != "." && $i_file != "..") { /* prevents getting information from parent directory */
                       $i_file_pieces = explode(".", $i_file);
                       if (strtolower($i_file_pieces[0]) == "index") {
                             $ext = "/index.".$i_file_pieces[1];
                       }
                   }
               }
               closedir($i_handle);
            }
        } else {
            //Here you can place "file not found" code
           $page = '404';
           $ext = 'php';
        }
    }
} else {
    //Here you can place "page include file not defined" code, e.g. the main page
    $page = 'main';
    $ext = 'php';
}

$include_page = $dir."/".$page.$ext;

?>


For example if I have a page called test.php in the folder $dir (here subpages), I can enter http://my_web_site.com/index.php?page=test (said that the code is put in index.php).

Then to actually include the actual page, I simply use
Code:
<?php include($include_page); ?>
pollux1er
Try to download the php manual. You will know more about that functions.
Related topics
site colse/open with php
Getting a URL with PHP
PHP - Error
changing output but not action="filename.php" ...H
Select a url for an image in image functions
PHP script problem
cURL wat is it??
php/sql question
Flash over php
Getting PHP variable to work in FCKeditor
rss 2.0 feeds
PHP Whos Online Code OR Page refresh..
learning HTML and PHP
removing DirectAdmin part of URL makes php code work
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.