Page 1 of 1

Get Method links.. With folder changer..

Posted: Thu Oct 31, 2002 7:05 am
by Darkside
//Alias codes for the folder and the page
if (!empty($_GET['folder'])) {
$folder = $_GET['folder'];
} else {
$folder = 'flash/';

}
if (!empty($_GET['flashpage'])) {
$flashpage = $_GET['flashpage'];
} else {
$flashpage = 'news';
}

//Include on the Index.php
<?php include $folder.'/'.$flashpage.'.php'; ?>

My frist question is there I away I can use 1 link to change both setting

eg

index.php?folder=flash[b][whatgoeshere][/b]page=news1

There for it the include would goto

<?php include flash/news1.php; ?>


Second is there away I can encode the folder name..?

eg

$f = "flash/";

if (!empty($_GET['folder'])) {
$folder = $_GET['folder'];
} else {
$folder = '$f';

Posted: Thu Oct 31, 2002 7:27 am
by twigletmac
To have more than one variable in a query string the most common way of doing it is by joining them with an ampersand (&) so:

Code: Select all

index.php?folder=flash&page=news1
then the $_GET array would contain both $_GET['folder'] and $_GET['page'].

I'm not too sure what you mean by encoding the folder name though.

Mac

Ive done it..

Posted: Thu Oct 31, 2002 7:34 am
by Darkside
Wot I didnt want is so that would could see..

index.php?folder=3dmax&page=news1


and work out that if you goto..

folder 3dmax and page news1 eg

/3dmax/news1.php

you would get the page on its own (- the css eg)

So wot Ive done is..

added an _ to my folder names..

eg

_flash
_3dmax
_forum
_admin

And done this..

<?php $address = "_"; >

and then this on my index..

<?php include $address.$folder.'/'.$flashpage.'.php'; ?>

Do you understand?

Posted: Thu Oct 31, 2002 7:45 am
by twigletmac
You could put all your folder names into an array like so:

Code: Select all

$folders = array(
	1 =&gt; '3dmax',
	2 =&gt; 'folder2',
	3 =&gt; 'folder3',
	4 =&gt; 'folder4'
);
now $folders[1] = '3dmax', $folders[2] = 'folder2', etc...

This means that you can change your links so that instead of having

Code: Select all

index.php?folder=3dmax&amp;page=news1
you could have

Code: Select all

index.php?folder=1&amp;page=news1
From within your code you would now do something like this:

Code: Select all

if (!empty($_GET&#1111;'folder']) &amp;&amp; isset($folders&#1111;$_GET&#1111;'folder']]) {
    $folder = $folders&#1111;$_GET&#1111;'folder']];
    if (!empty($_GET&#1111;'flashpage'])) { 
        $flashpage = $_GET&#1111;'flashpage']; 
    } else { 
        $flashpage = 'news'; 
    }    
} else { 
    $folder = 'flash/';
    $flashpage = 'index';
}
This way you aren't showing anyone your folder names and you can also prevent them from being able to access other folders within your site that aren't specifically named in the $folders array. (in the code above && should be changed to &&)

Mac

Posted: Thu Oct 31, 2002 7:47 am
by volka
you can also place those files outside your visible webtree as long as php is able to include that file (i.e. the file is readable for it)