PHP class working incorrectly
Posted: Wed Dec 02, 2009 4:01 pm
I am in the process of creating a PHP class that creates a HTML page but only displays content if the user has a certain web browser, version and has both JavaScript and cookies enabled.
This is my index.php:
And this is the file it requires (classes.php):
I am using Firefox 3.5 and switched JavaScript off, restarted Firefox and then loaded index.php. To my dismay, $content remained unchanged (when it should have changed on Line 38).
I would be grateful if someone could point out what I've done wrong! Thanks in advance for any help/tips/pointers
This is my index.php:
Code: Select all
<?php
require("classes.php");
$page = new page;
$page->display_page();
?>Code: Select all
<?php
class page {
public $getBrowser;
public $browser;
public $version;
public $javascript;
public $cookies;
public $browserCompatible = false;
public $title = "My Page";
public $style = "stylesheet.css";
public $header = "<h1>Header</h1>";
public $content = "<p>Some content</p>";
public $footer = "<p>Footer</p>";
public function display_page() {
echo "<html>\n<head>\n";
$this->display_title();
$this->display_styles();
echo "</head>\n<body>\n";
$this->display_header();
$this->check_compatibility();
$this->display_content();
$this->display_footer();
echo "</body>\n</html>\n";
}
public function check_compatibility() {
$this->getBrowser = get_browser(null, true);
$this->browser = $this->getBrowser['browser'];
$this->version = $this->getBrowser['version'];
$this->javascript = $this->getBrowser['javascript'];
$this->cookies = $this->getBrowser['cookies'];
switch($this->browser) {
case "Firefox":
if ($this->version < '1.0') {
$this->content = "<p>You need at least Firefox 2.0 to use this site!</p>";
} else if ($this->javascript != true) {
$this->content = "<p>You need JavaScript enabled to use this site!</p>";
} else if ($this->cookies != true) {
$this->content = "<p>You need cookies enabled to use this site!</p>";
} else {
$this->browserCompatibile = true;
}
break;
default:
$this->content = "<p>You need Internet Explorer 7+, Firefox 1+, Safari 1.2+, Chrome 0.2+ or Opera 7.6+ to use this site!</p>";
}
}
public function display_title() {
echo "<title>".$this->title."</title>\n";
}
public function display_styles() {
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"".$this->style."\"></link>\n";
}
public function display_header() {
echo "<div id=\"header\">".$this->header."</div>\n";
}
public function display_content() {
echo "<div id=\"content\">".$this->content."</div>\n";
}
public function display_footer() {
echo "<div id=\"footer\">".$this->footer."</div>\n";
}
}
?>I would be grateful if someone could point out what I've done wrong! Thanks in advance for any help/tips/pointers