Page 1 of 1

n00b question.

Posted: Fri Apr 19, 2002 5:26 am
by Jim
Hola!

Yes, I'm a total PHP n00b (but it's all good, right?) and I'd like a little bit of help if you guys could offer it :)

I'm creating a web site with several different themes (just like this one. Yes, I got the idea from you guys :)) and using includes I'm making it a very simple process.

This is my big thing:

I figured I'd rather not rewrite all of my information on to a bunch of new pages over and over and over...

Rather than copying and pasting information on one page to another page within a different theme, I want to use includes. Well, that's simple enough. But to make it even easier, rather than creating separate pages with a specific include (i.e.- one page for cat.php and one for dog.php) I'd like to use a SINGLE page that prints a certain page according to the link.

On the target page (we'll call it page.php, k? ;)) I have this:

<?
print $name
?>

In the url, I put this (this format... I know my site is not mysite.com :)):

http://www.mysite.com/page.php?$name=target.php

So what I'm trying to do is take the include named "target.php" and have it show up on the page. Will that work? Thanks for your help!

yeah

Posted: Fri Apr 19, 2002 5:47 am
by Oxy
You don't want to use this http://www.mysite.com/page.php?$name=target.php because it allows people to view any file on your server, instead change your code to this :

Code: Select all

<?

include "$name.php";

?>
That means the viewers can only view files with a .php extension

Posted: Fri Apr 19, 2002 1:52 pm
by quamper

Posted: Fri Apr 19, 2002 8:54 pm
by Jim
I'm not interested in using templates right now.

I'm having fun doing it the way I'm doing it. I'm both the HTML designer and wannabe PHP scripter for the site, so I'm not worried about separating PHP and HTML.

I just want to be able to call up a certain include name with something in the URL.

I figured http://www.mysite.com/file.php?$name=NAME would do it. I was hoping that the $name=NAME would name the variable for me, and then use that name in this:

<?
require $name
?>

Can I do that? It doesn't seem that hard, but I'm not sure how it might work.

*edit*

Now that I think of it, I can do this much the same way as using the "get" method in forms. Wow. I suck at this.

Thanks guys!

*edit^2*

Hehe, it worked!

Posted: Sat Apr 20, 2002 3:34 am
by hex
One thing I would say is that you should use ?name=NAME and not ?$name=NAME the dollar ($) isn't needed there.

Also, these themes will only be per-session, use cookies to save preferences.

Re: yeah

Posted: Sat Apr 20, 2002 5:21 am
by chiefmonkey
Oxy wrote:You don't want to use this http://www.mysite.com/page.php?$name=target.php because it allows people to view any file on your server, instead change your code to this :

Code: Select all

<?

include "$name.php";

?>
That means the viewers can only view files with a .php extension

Wouldn't this be classed as a security risk, after all a malicious user could enter
http://www.mysite.com/page.php?name=htt ... ntvars.php and try to grab some information

George