...

View Full Version : Newbie to PHP...



adrianman
05-19-2004, 03:21 AM
I'm new to PHP...
Anyway, I need help with a scriot on index.php. I have a script that has files stored in the /pages directory and let's say if dsppoou.php was in there, I could go to index.php?page=dsppoou.php.
I want help redirecting the plain index.php to ?page=index.
Here is the code if it helps:


<?
// Get PAGES
$directory = "pages/";
$pages = array();
if ( $dir = opendir( $directory ) ) {
while( ($file = readdir( $dir ) ) !== false ) {
$added = false;
foreach( $pages as $p ) {
if ( $file == $p ) {
$added = true;
}
}
if ( $added ) {
continue;
}
$pages[count($pages)] = $file;
}
}
for ( $x=0; $x<=count($pages); $x++ ) {
if ( $admin != "" ) {
break;
}
if ( $x == count($pages) ) {
AddTable("Error!","The specified page could not be found. Please check the GET ID.");
break;
}
if ( $page.".php" == $pages[$x] ) {
include("pages/".$pages[$x]);
break;
}
}
?>

Thanks for your time. :D

l3vi
05-19-2004, 04:20 AM
Hmmm, you did this a strange way... lotsa script for what I think your trying to do... Are you trying to read a new php file as a txt file? Why not just use include? And what are the arrays for? Heres some code you can use:


<?php
if(isset($_GET['page'])){
$page="$_GET[page]";
}else{
$page="home";
}

if(is_file("./Pages/$page.php"){
$page=$page;
}else{
$page="home";
}

include("./Pages/$page.php");
?>


This script would of course require you to have a page labelled home at all times, of course you can alter it to have the default set to anything you want.

Spookster
05-20-2004, 07:42 AM
You need to read our posting guidelines section 2

http://www.codingforums.com/postguide.htm



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum