...

View Full Version : Pages...



primexx
09-17-2005, 05:40 AM
Ok, so, you know how you can use switch, or if, or arrays to make pages? like act=whateverpage?

well, can anyone give me a detailed explination of how the arrays method works?


oh and also, how do you make something like act=page&value=something?


thanks in advanced.

Fou-Lu
09-17-2005, 06:40 AM
querystring: script.php?page=page&action=do&value=whatever is access using the $_GET or $_REQUEST superglobals. Using $_GET['action'] on the above querystring will return a value of 'do' to the value.

Now, it depends on what you are doing for what would be the best method to use. If your planning on running an include() or require() I'd suggest you use both an array for the pages allowed, and a switch. If your embedding different actions into your script, I'd use an if statement.
Here's what I mean:
For inclusions:


<?php
$allowed_pages = array ('index.php', 'members.php', 'news.php');

if (!empty($_GET['page']) AND in_array($_GET['page'], $allowed_pages))
{
include('./' . $_GET['page']);
}
else
{
die ('The page requested is not available.');
}

Not exactly the most secure, but would suffice. Now, for embedded, which is what I use most frequently:


<?php

if (empty($_REQUEST['action']))
{
$_REQUEST['action'] = 'default';
}

if ($_REQUEST['action'] == 'default')
{
// Default page code
}
if ($_REQUEST['action'] == 'shownews')
{
// Show the page news code
}
if ($_REQUEST['action'] == 'showarticle')
{
// Show just the article requested (we would need more varibles for this)
}
?>

Does that help you any?

primexx
09-17-2005, 07:02 AM
actually, not exactly what I was looking for, but I'll use some other resources and work with that.

Thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum