Jump to content

Help with simple php file


mrk112

Recommended Posts

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

[code]<?php

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">

<head>
    <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" />
</head>

<body>

    <div id="header">

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

    <div id="navigation">

        <ul>
            <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>
        </ul>

    </div>

    <div id="content">

        <?php include "$filename" ?>

    </div>

</body>

</html>
[/code]

Here's the info.dat file:

[code]1;home.txt;style1.css;Home Page;
2;applications.txt;style1.css;Applications;
3;formats.txt;style1.css;Formats;
4;linux.txt;style1.css;Linux;[/code]
Link to comment
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..

Thanks..
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.