Well, I think it's the recursive function. This is my first post so might as well make it a hard one. On my local server, I am getting the results I want. My webhost isn't the most agreeable however.
Anyway, I am stumped so thanks to anyone with any suggestions.
The Task:
I was trying to display an error message when a page couldn't be found in the database. Eg: index.php?page=home is valid, but index.php?hom is not. My local wamp server is displaying the "Page Not Found" page (stored in the database) but my webhost is displaying an Internal Server Error.
There are essentially 3 files I would like to focus on. I have trimmed the files down to relevant content. ( ??? implies missing content)
/index.php
/includes/header.php
/classes/page.php
index.php
PHP Code:
<?php include_once('includes/header.php'); ?> ??? <?php $page->display(); ?> ???
header.php
PHP Code:
<?php ??? // filename() returns the name of the current script if(filename() == 'index.php') { if(isset($_GET['page']) && !empty($_GET['page'])) { $ptitle = $_GET['page']; $page = new Page($ptitle); } else if(!isset($_GET['page'])) $page = new Page('Home'); else $page = new Page('Page Not Found'); } ?> ??? <li><a href="index.php?page=Home">Home</a></li> ???
page.php
PHP Code:
<?php class Page { ??? const ERROR_PAGE = 'Page Not Found'; ???
public $title; public $content; public $image; public $redirect; public $meta_description; public $meta_keywords; public $timestamp; ??? // Retrieve the page from the database private function retrieve($title='') { if(empty($title)) $title = $this->title; // Sanitize required data $title = $this->database->sql_safe($title); $query = "Select * From $this->table Where $this->pkey = '$title'"; if($this->database->query($query)) { if($this->database->num_rows() > 0) { $data = $this->database->get_result_array(); $this->title = $data['title']; // Replaces the title with the one stored in the database $this->content = $data['content']; $this->image = $data['image']; $this->redirect = $data['redirect']; $this->timestamp = $data['timestamp']; // If the meta tags have been set for the page, overwrite the default ones if($data['meta_description'] != null) $this->meta_description = $data['meta_description']; if($data['meta_keywords'] != null) $this->meta_keywords = $data['meta_keywords']; return true; } else $this->retrieve(self::ERROR_PAGE); } else return false; }
??? // Redirect the page to the specified url if it has been set private function redirect_page() { if($this->redirect != null) { $this->outputbuffer->clean(); // Clear the output buffer header('Location: ' . $this->redirect); exit(); } else return false; } // Print / Redirect the page public function display() { if(!$this->redirect_page()) $this->print_page(); } ?>
I think that's understandable enough without any further explanation. Also, if you have any recommendations on doing things differently, please say. :-)
|