Jump to content


This topic is now archived and is closed to further replies.


Help with simple php file

Recommended Posts

Could anyone tell me why this code doesn't want to work?


if (empty($_GET['page'])) {

    $page = "1";


$data = file_get_contents("info.dat");

$exploded = explode(";", $data);

for ($i=0; sizeof($exploded) > $i && $found != true; $i++) {

    if (strcmp($page, $exploded[$i]) == 0 && is_file("exploded[$i+1]")) {

        $found = true;
        $filename = "exploded[$i+1]";
        $style = "exploded[$i+2]";
        $title = "exploded[$i+3]";

    } else {

        $filename = "404.txt";
        $style = "style1.css";
        $title = "Error 404: Page not found";




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-GB" xml:lang="en-GB">

    <meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
    <title><?php echo "$title" ?></title>
    <link rel="stylesheet" href="<?php echo "$style" ?>" type="text/css" />


    <div id="header">

        <h1>u02mah5's site...</h1>
        <h2>dedicated to all things open source</h2>

    <div id="navigation">

            <li><a href="">Home Page</a></li>
            <li><a href="">Applications</a></li>
            <li><a href="">Formats</a></li>
            <li><a href="">Linux</a></li>


    <div id="content">

        <?php include "$filename" ?>




Here's the info.dat file:

[code]1;home.txt;style1.css;Home Page;

Share this post

Link to post
Share on other sites
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]this code doesn't want to work[/quote] Please try to be a little more specific.

Share this post

Link to post
Share on other sites
Sorry, I'll try and be more specific..

The part where it seems to be falling over is in the second condition of the if statement but I don't know what the problem is.. I took it out and the file worked fine but after putting it back in I get the 404 page for everything..

Also, I've been thinking about implementation overall.. Currently, the site uses addresses like index.php?page=1 etc which is fine so far.. The php file checks to see if it's listed as a valid page in my info.dat and also checks if the include file exists.. If all that is ok then it will load the appropriate page.. But then when I'm doing links I manually hard code them in (like the link I just mentioned). If I want to add pages then I'd have to edit the info.dat file and then manually edit the navigation etc.. Can anyone think of a better way of organizing the site? Bearing in mind that I'm going to have main pages (which I want menu entries on all pages) and sub pages..


Share this post

Link to post
Share on other sites
Tried putting the $ in front of your variable name -- or is that a variable name? "exploded[$i+1]"

if (strcmp($page, $exploded[$i]) == 0 && is_file("exploded[$i+1]")) {

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.