Jump to content


Help with simple php file

  • Please log in to reply
3 replies to this topic

#1 mrk112

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 03 March 2006 - 08:16 PM

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:

1;home.txt;style1.css;Home Page;

#2 kanikilu

  • Members
  • PipPip
  • Member
  • 29 posts
  • LocationDallas, TX

Posted 03 March 2006 - 09:08 PM

[!--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.

#3 mrk112

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 03 March 2006 - 09:58 PM

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


#4 michaellunsford

  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 04 March 2006 - 02:24 AM

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]")) {

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users