Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can !
Moderator: General Moderators
MikeM
Forum Newbie
Posts: 5 Joined: Thu Jan 25, 2007 11:09 pm
Post
by MikeM » Thu Jan 25, 2007 11:14 pm
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hello everyone,
For the first time, I installed PHP 5 and Apache on my windows xp machine.
Everything worked fine except for classes..which php seems to spit out as text.
Are there any known issues , or did I miss something in the php.ini file?
Here's the code I'm *trying* to use:Code: Select all
class Page
{
var $page;
function Page($template = "template.html") {
if (file_exists($template))
$this->page = join("", file($template));
else
die("Template file $template not found.");
}
function parse($file) {
ob_start();
include($file);
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
function replace_tags($tags = array()) {
if (sizeof($tags) > 0)
foreach ($tags as $tag => $data) {
if (substr($data, 0, 3) == 'inc') { $data = substr($data, 3, strlen($data)); $data = (file_exists($data)) ? $this->parse($data) : $data; }
$this->page = ereg_replace("{" . $tag . "}", $data,
$this->page);
}
else
die("No tags designated for replacement.");
}
function output() {
echo $this->page;
}
}
Any help or input would be greatly appreciated
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jan 25, 2007 11:19 pm
Is this the whole file, in its entirety, without tags or anything else? Did you
include() this file?
MikeM
Forum Newbie
Posts: 5 Joined: Thu Jan 25, 2007 11:09 pm
Post
by MikeM » Thu Jan 25, 2007 11:21 pm
Nevermind lol, I forgot to enable shorthand tags in the ini file, so everything between <? and ?> was read as text.
I guess I should look into the obvious reasons before asking for help.
Oh and sorry for not reading the posting guidelines, usually I check the sticky first.. forgot to do that.
Thanks again, Mike.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jan 25, 2007 11:25 pm
Short tags are bad.
MikeM
Forum Newbie
Posts: 5 Joined: Thu Jan 25, 2007 11:09 pm
Post
by MikeM » Thu Jan 25, 2007 11:27 pm
I know, I'm gonna go through and get rid of them.
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Wed Jan 31, 2007 6:56 pm
And hopefully you have already went back and disabled them so you know exactly where you need to fix stuff. While you are in there make sure register_globals is off.
MikeM
Forum Newbie
Posts: 5 Joined: Thu Jan 25, 2007 11:09 pm
Post
by MikeM » Wed Jan 31, 2007 7:51 pm
Globals is when php turns $_GET[somevariable] into $somevariable right?
Why would I wanna turn those off?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Jan 31, 2007 9:29 pm
Because those are bad too. It makes lazy programmers, and it can be turned off on servers as well. If you write your code such that you assume they are off, your code will be more portable. However, you should still initialized the variables.
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Thu Feb 01, 2007 12:14 am
MikeM wrote: Globals is when php turns $_GET[somevariable] into $somevariable right?
Why would I wanna turn those off?
Because they are horribly insecure and not portable.
MikeM
Forum Newbie
Posts: 5 Joined: Thu Jan 25, 2007 11:09 pm
Post
by MikeM » Thu Feb 01, 2007 12:18 am
oh...ok then. Thanks for the tip
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Thu Feb 01, 2007 12:19 am
You know, an easy, sensible way to turn $_GET[somevariable] into $somevariable is
Code: Select all
$somevariable = "";
if(isset($_GET['somevariable'])) $somevariable = $_GET['somevariable'];
Try getting an error with that baby!
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Thu Feb 01, 2007 12:23 am
superdezign wrote: You know, an easy, sensible way to turn $_GET[somevariable] into $somevariable is
Code: Select all
$somevariable = "";
if(isset($_GET['somevariable'])) $somevariable = $_GET['somevariable'];
Try getting an error with that baby!
Why not use the braces? If you are going to write it like that, just use ternary...
Code: Select all
<?php
$getvar = isset($_GET['var']) ? $_GET['var'] : '';
?>
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Thu Feb 01, 2007 12:24 am
Everah wrote:
Why not use the braces? If you are going to write it like that, just use ternary...
Code: Select all
<?php
$getvar = isset($_GET['var']) ? $_GET['var'] : '';
?>
*Gasp* I did not know php supported that.
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Thu Feb 01, 2007 1:21 am
Learning new stuff every day...