Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2004
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Newbie to PHP...

    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:
    PHP Code:
    <?
    // 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.

  • #2
    Regular Coder
    Join Date
    Jan 2003
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 Code:
    <?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.
    Last edited by l3vi; 05-19-2004 at 04:23 AM.

  • #3
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    You need to read our posting guidelines section 2

    http://www.codingforums.com/postguide.htm
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •