Jump to content

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