Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

119 users online



Tutorial: page.php?page=blah / query strings / easy template tutorial (UPDATED)

Tutorial: page.php?page=blah / query strings / easy template tutorial (UPDATED)

Currently viewing this thread: 1 (0 members and 1 guests)


Page 4 out of 15
DirectWD

DirectWD

Status: Offline!

[QUOTE][i]Originally posted by TrigBoy [/i]
[B]yeh it could be used for comparing.

eg

[PHP]
If($_1337['DirectWD'] > $_1337['TrigBoy'])
{
echo "Neg";
}
else
{
echo "Thats more like it";
}
[/PHP][/QUOTE]

$_1337 is not a registered global unless you are using register globals ON in which your if statement still would be incorrect.

___________________

» DirectWD HTML / JavaScript / XHTML / CSS / PHP / MySQL
Direct Web Design

gromy

gromy

Status: Offline!

isn't this:

PHP:

<?php
include $page;
?>

a lot faster than a switch statement?
It's probably hardly noticeable with just a few cases, but if there were hundreds of cases...
To make it a little more secure (sorta like KungPaoChicken was talking about) having it point to a folder like pages or includes so all pages that could be included would be in that folder:

PHP:

<?php
$page2include 
"includes/$page.php";
include 
$page2include;
?>

Does anybody know if there is anything wrong with doing it this way?

Huscy

Huscy

my biography
Status: Offline!
PHP:


<?
 $links 
= array(
'csstut_basic.php',
'csstut_scrollbars.php'
); 
if (isset(
$_GET['page'])) 

    
$page $_GET['page'];
    if(
in_array($page,$links)) 
    { 
    include(
"$page"); 
    } 
    else 
    { 
    echo 
"bog off!"
    };
}
else 

include(
"index_content.php"); 
}; 
?>

surely that works fine, and if you use a db instead of an array you can update it from anywhere, w/out adding a new case statement?

___________________

Infinite Fire - Photoshop, PHP, HTML, CSS and Webmaster Tutorials - Web Design Centre
Photoshop Tutorials | PHP Tutorials | HTML Tutorials | Webmaster Tips and Tricks
Buy Cheap Digital Cameras!

gromy

gromy

Status: Offline!

But it's going to have hundreds, probably thousands of pages. I think having to define an array with a thousand variables everytime a page is called would slow down the cpu.

Huscy

Huscy

my biography
Status: Offline!

hmmm possibly, but most people here dont have 1000+ pages on their site, i have approx 50 and i see no loss in speed, and is v.secure - i see your point though

___________________

Infinite Fire - Photoshop, PHP, HTML, CSS and Webmaster Tutorials - Web Design Centre
Photoshop Tutorials | PHP Tutorials | HTML Tutorials | Webmaster Tips and Tricks
Buy Cheap Digital Cameras!

lntora

lntora

Status: Offline!

Came in from google after doing a search for template tuttorials. I was wondering if anyone could give a code example of this if the content is stored in mySQL? Or maybe how to read a template from a file into a string, then just replace the variables there with the content from the database, then output to the browser.

Any help/examples would be greatly appreciated, thank you.

DAZZ1

DAZZ1

Status: Offline!

what about something like:

http://mysite.com/index.php?HELLO

Varible = HELLO

Is that possible???

Schitzophreniic

Schitzophreniic

Status: Offline!

as i do hate to bump this thread, i cant figure out how to not have to use the varriable.. so it is like yoursite.com/?news, yoursite.com/?forum, ect, ect...

___________________

....

Dan1

Dan1

TF Retiree
Status: Offline!

Well, the default page is automatically index.php, so having ?varstuff is ok. As to how to do it, read the following.

PHP:


<?php
$query 
$_SERVER["QUERY_STRING"];
isset(
$query) ? $query.".txt" "default.txt";
if(
file_exists($query))
{
include 
$query;
}
else
{
echo 
"Error!";
}
?>

$_SERVER["QUERY_STRING"]; is the equivalent of everything after the ?.

underburn

underburn

Status: Offline!

My site's pages are located trough multiple directories, So I tried the code, and it didnt work. I think that may be the problem because when I put in

www.mysitehere.com/test.php?id=contact

for example, it just takes me to my default page. I tried using my absoloute path as well and it didnt work... here is what I have in test.php

Code:


<?php
switch( $HTTP_GET_VARS['what'] ) {

case 'contact' :
include '/home/virtual/site73/fst/var/www/html/site/contact/index.php';
break;
case 'contact' :

default:
include 'main.php';
break;
}
?>

___________________

Signature Suspended as it is in violation with the signature rules

Page 4 out of 15
Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0102 seconds.