Jump to content

Default Case for Dynamic Content


bachya

Recommended Posts

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! :)
Link to comment
https://forums.phpfreaks.com/topic/11890-default-case-for-dynamic-content/
Share on other sites

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.
[!--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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.