n00b question.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

n00b question.

Post 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!
Oxy
Forum Newbie
Posts: 17
Joined: Fri Apr 19, 2002 5:47 am
Location: U.K
Contact:

yeah

Post 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
User avatar
quamper
Forum Newbie
Posts: 1
Joined: Fri Apr 19, 2002 1:52 pm

Post by quamper »

Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post 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!
User avatar
hex
Forum Commoner
Posts: 92
Joined: Sat Apr 20, 2002 3:20 am
Location: UK

Post 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.
User avatar
chiefmonkey
Forum Commoner
Posts: 25
Joined: Sat Apr 20, 2002 5:21 am
Location: Glasgow UK

Re: yeah

Post 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
Post Reply