What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » PHP Question

PHP Question
Author: Message:
stoshrocket
Senior Member
****

Avatar
formerly methos

Posts: 748
Reputation: 31
34 / Male / Flag
Joined: Aug 2005
RE: PHP Question
quote:
Originally posted by Eddie
Yeah the method i used to use followed the logic from your first page, but instead of having seperate variable things like you have, you had all your page names.

So for example, we used to use a random format, for our old site we used .hz. So in the php code we would have it realising the format name, posting it like any other include but only reading the page names from 'test', 'test1', 'test2' which it would realise are test.hz, test1.hz and test2.hz, and it would show as index.php?p=test or index.php?p=test1

Your original post does this, but in a way that is slightly different and not completely how i wanted.
Ah! Very interesting, although it's not 100% secure it would stop a lot of potential malicious users... A simple way to do this would be to get the page variable, then add the extension on and include this, which in code form would be:

php code:
$extension = ".hz";
$llama = "$_GET['page']"."$extension";

include ($llama);

Line by line, this defines your extension, then retreives your page variable and attaches the extension to the end and includes the page that this is called. You could probably do with checking the file exists using file_exists to prevent any messy error pages, which could easily be done by shoving it into an if statement and having the error include in the else bracket:

php code:
$extension = ".hz";
$llama = "$_GET['page']"."$extension";

if(file_exists($llama) == TRUE){
include ($llama);
}
elseif(file_exists($llama) == FALSE){
include("error.php")
}

This would mean a link to include page1.hz would look like this btw:
html code:
<a href="?page=page1">page one</a>

NB:Edited link, it stated it should be "page1" when it should be "?page=page1", sorry!

SIDE NOTE:
To increase security, might be worth incresing the size of the random extension and throwing a few numbers in there, this way it can't be stumbled upon as easily =)

FURTHERMORE:

If you wanted to keep all of your includes in a seperate folder or altogether seperate directory, you could assign a variable called $dir and then set this to be your include folder directory and attach it to $llama in the same way... ie, it becomes

php code:
$dir = "./some/file/dir"; //extra line to define dir
$llama = "$dir"."$GET_['page']"."$extension"; //new $llama line

FURTHERMORE SIDE NOTE:

You could also have different subfolders and a seperate GET variable if you REALLY wanted... So lets take that example. Imagine you had a database of users all stored in nice text files. Each user has their own folder in the dir ./data/users/ so a user with username methos would have a folder directory ./data/users/methos/ with all their user data in. Say we had a profile page that we wanted to include, and it was stored within the users data folder, we'd have two GET variables: user and page, and we could use the following code to find the correct profile:

php code:
$extension = ".hz"; //sets the extension variable

//this two line section defines the two variables included in the URL, you don't have to do this - you could just substitue the variables in the $llama variable for the values defined here, but this way it shows it nice and clearly and allows for explanation and comments...
$username = $_GET['user'];
$page = $_GET['page'];

//the directory that the username folders will be in
$dir = "./data/users/";

//defines the path of the file to include in the following format: directory-user-folders-are-in/user-folder-name/page-to-include.extension
$llama = "$dir"."$username"."$page"."$extension";

//checks whether this file exists, if it does include it, if it doesnt include the page error.php
if(file_exists($llama) == TRUE){
include ($llama);
}
elseif(file_exists($llama) == FALSE){
include("error.php")
}

Which for the url (or link to the url of) "http://www.bbq.com/index.php?user=methos&page=profile" would have the page index.php and it would include the file ./data/users/methos/profile.hz

Hope all this helps :D

MASS EDIT: I've changed a couple of explanations, corrected some spelling errors and added some php comments to specifically explain coding =)

This post was edited on 03-31-2009 at 06:38 PM by stoshrocket.
formerly methos
03-31-2009 05:30 PM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
PHP Question - by Eddie on 03-31-2009 at 02:29 PM
RE: PHP Question - by matty on 03-31-2009 at 03:42 PM
RE: PHP Question - by stoshrocket on 03-31-2009 at 03:48 PM
RE: PHP Question - by Eddie on 03-31-2009 at 04:28 PM
RE: PHP Question - by MeEtc on 03-31-2009 at 04:43 PM
RE: PHP Question - by Eddie on 03-31-2009 at 04:49 PM
RE: PHP Question - by stoshrocket on 03-31-2009 at 05:07 PM
RE: PHP Question - by Eddie on 03-31-2009 at 05:16 PM
RE: PHP Question - by stoshrocket on 03-31-2009 at 05:30 PM
RE: PHP Question - by Eddie on 03-31-2009 at 05:47 PM
RE: PHP Question - by stoshrocket on 03-31-2009 at 05:49 PM
RE: PHP Question - by davidpolitis on 04-02-2009 at 07:43 AM
RE: PHP Question - by Eddie on 04-02-2009 at 08:33 AM
RE: RE: PHP Question - by davidpolitis on 04-02-2009 at 12:52 PM
RE: PHP Question - by stoshrocket on 04-02-2009 at 12:10 PM
RE: PHP Question - by segosa on 04-02-2009 at 10:05 PM
RE: RE: PHP Question - by davidpolitis on 04-03-2009 at 06:49 AM
RE: RE: RE: PHP Question - by segosa on 04-03-2009 at 08:09 AM
RE: PHP Question - by stoshrocket on 04-02-2009 at 11:23 PM
RE: PHP Question - by Eddie on 04-03-2009 at 06:50 AM
RE: RE: PHP Question - by davidpolitis on 04-03-2009 at 06:55 AM
RE: PHP Question - by NanaFreak on 04-03-2009 at 06:54 AM
RE: PHP Question - by NanaFreak on 04-03-2009 at 07:06 AM
RE: RE: PHP Question - by davidpolitis on 04-03-2009 at 07:16 AM
RE: PHP Question - by Felu on 04-03-2009 at 09:37 AM
RE: RE: PHP Question - by davidpolitis on 04-03-2009 at 10:15 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On