Help - Search - Members - Calendar
Full Version: PHP help
ieXbeta Board > Tech > Developer Center
Pr0digy
Okay, I don't know an ounce of PHP but the template I am using for my gaming clan's website requires it.

I cannot navigate to the selected page, and I'm afraid my trial-and-error is running out.

CODE

    <?php
    $action = $_GET['action'];

    $pages = array
    (
      'roster'   => './roster.php',
      'matches' => './matches.php',
      'downloads' => './downloads.php',
      'servers' => './servers.php',
      'gallery' => './gallery.php',
      'sponsors' => './sponsors.php',
    );

    if(strlen($pages[$action]) > 0)
    {
      require $pages[$action];
    }
    else
    {
      require './index.php';
    }
    ?>


The above is my current code that I rewrote because the code that I got with the template didn't work either.

Below is the original code:

CODE
<?php
switch($page) {
default:
include('news.php');
  
break; case "sponsors":
include('sponsors.php');

break; case "matches":
include('matches.php');

break; case "news":
include('news.php');

break; case "roster":
include('roster.php');

break; case "gallery":
include('gallery.php');

break; case "downloads":
include('downloads.php');

break; case "servers":
include('servers.php');

break; case "gallery":
include('gallery.php');

$page = urldecode($GET["page"]);

}
?>


Can someone help me?
DangerousDave86
Your code looks like it should work.

Your links should point to ?action=roster and such.

What I can't understand from your code is, why your default page is index.php.

Surely that code should be IN index.php. and your default should be called home.php or something?
Pr0digy
My links point to ?page=roster

I don't know. That is how I received the template. Basically, I was gonna use this because it looked good and it'd help me a little with PHP, but I have failed at the second part.

When it is IN index.php, it makes a neverending page. Seriously, the page keeps repeating itself until I close out the tab.
Phonics Monkey
QUOTE(Pr0digy @ Aug 27 2007, 21:26) *

My links point to ?page=roster

I don't know. That is how I received the template. Basically, I was gonna use this because it looked good and it'd help me a little with PHP, but I have failed at the second part.

When it is IN index.php, it makes a neverending page. Seriously, the page keeps repeating itself until I close out the tab.

that would be the if(statement) infinite loop you have there (it can never reach 0). Go back to the switch case statement in the original code, and verify the relevant paths. Switch case statements are (much) faster and don't loop.
Pr0digy
What does all that mean?
DangerousDave86
Your links should be action=page, not page=page. Your variable is looking for $_GET['action'].

Index.php
CODE
    <?php
    $action = $_GET['action'];

    $pages = array
    (
      'home' => './home.php',
      'roster'   => './roster.php',
      'matches' => './matches.php',
      'downloads' => './downloads.php',
      'servers' => './servers.php',
      'gallery' => './gallery.php',
      'sponsors' => './sponsors.php',
    );

    if(strlen($pages[$action]) > 0)
    {
      require $pages[$action];
    }
    else
    {
      require $pages['home'];
    }
    ?>

That code will work. Index.php will now be a piece of software, instead of a html file. The default page will now be home.php, not index.php. Links should be ?action=page (page being roster, sponsors, home, etc.).
Hope this clears things up.

Additional explanation.. index.php contains no content at all, so for any page to be displayed, even the default, it must include another file, in the case of a default page, when no action=page has been passed to the server, or the page doesn't exist, 'home.php' gets included (actually required, same thing really). If a valid action has been passed to it, then that page is included.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.