Get Method links.. With folder changer..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Darkside
Forum Commoner
Posts: 43
Joined: Wed Oct 30, 2002 4:18 pm

Get Method links.. With folder changer..

Post 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';
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Darkside
Forum Commoner
Posts: 43
Joined: Wed Oct 30, 2002 4:18 pm

Ive done it..

Post 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?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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)
Post Reply