bachya Posted June 13, 2006 Share Posted June 13, 2006 Hi all,I'm fairly new to PHP, and I have a question about dynamic content that's loaded through a URL variable. My site uses a line like this:<?php include("$_GET[article].html") ?>...to dynamically include text into a laid out page (in a URL like www.mysite.com/articles.php?article=34). I like this, because it's simple (whereas, in ASP, I would have to have a large case statement with every possible article). However, I'm wondering if it's possible to have "default content" should someone enter something like: www.mysite.com/articles.php (no variable on the end).Is this possible, while STILL keeping intact my one-line inclusion from above? Or is something like a case statement the only way to have "default content?"Thanks! :) Quote Link to comment https://forums.phpfreaks.com/topic/11890-default-case-for-dynamic-content/ Share on other sites More sharing options...
nogray Posted June 13, 2006 Share Posted June 13, 2006 you can use a small if statement like[code]<?PHPif (isset($_GET[article])){ php include("$_GET[article].html");}else { echo "default content";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11890-default-case-for-dynamic-content/#findComment-45108 Share on other sites More sharing options...
trq Posted June 13, 2006 Share Posted June 13, 2006 You really should be checking the existance of any file before you try to include it anyway, otherwise your current setup has a [b]major[/b] security hole in your site.All you need do is check the file and querystring exist, if it does, include it, otherwise load a default. eg;[code]if (isset($_GET[article])) { if (file_exists($_GET[article]."html")) { include $_GET[article]".html"; } else { include "default.html"; }} else { include "default.html";}[/code]PS: All this can easily be done in asp also. Quote Link to comment https://forums.phpfreaks.com/topic/11890-default-case-for-dynamic-content/#findComment-45109 Share on other sites More sharing options...
bachya Posted June 14, 2006 Author Share Posted June 14, 2006 [!--quoteo(post=383356:date=Jun 13 2006, 12:51 PM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Jun 13 2006, 12:51 PM) [snapback]383356[/snapback][/div][div class=\'quotemain\'][!--quotec--]You really should be checking the existance of any file before you try to include it anyway, otherwise your current setup has a [b]major[/b] security hole in your site.All you need do is check the file and querystring exist, if it does, include it, otherwise load a default. eg;[code]if (isset($_GET[article])) { if (file_exists($_GET[article]."html")) { include $_GET[article]".html"; } else { include "default.html"; }} else { include "default.html";}[/code]PS: All this can easily be done in asp also.[/quote]How would I accomplish the above in ASP? For whatever reason, ASP is slightly more confusing to me... Quote Link to comment https://forums.phpfreaks.com/topic/11890-default-case-for-dynamic-content/#findComment-45663 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.