PhP Article Output

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
no_memories
Forum Contributor
Posts: 145
Joined: Sun Feb 01, 2004 7:12 pm
Location: New York City

PhP Article Output

Post by no_memories »

I'm new to PhP.

I am interested in setting up an article directory so that specific article(s) can then be called into a given template.

So say I have directory "A" something like http://test.me.com/articles/

I would then have files named something like atcl0001.htm, atcl0002.htm, atcl0003.htm, etc in the above directory.

Then I have a link on another page page that calls a specific article within that article directory.

The link might look like http://test.me.com/articles.php?getid=105 and would load the target article into this example template page.

The result would be I only need 1 template page to output the given article directory.

What I would like to know, is there an easy way to impliment something like this?

I'm sure there are several ways and easy to use PhP scripts. I'm just so PhP ignorant, I am not sure where to begin.

BTW, little snipbits of code doesn't help me at all at this point. I could really use an entire script to understand what is going on with something like this.

Thanks for any help
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Just read the variable in the url - i.e. $_GET[getid] and then this will relate to the given file, for example your files maybe named:

artical_1.php
artical_2.php
etc

Using the varible value you can construct a file name and path i.e.:

$filename = "path/to/articals/artical_".$_GET[getid].".php";

Then do some checks to see if this file exists and include the page if it does

if(file_exists($filename)){ #makes sure the file exists
include($filename);
}else{
echo "Invalid artical";
}
User avatar
no_memories
Forum Contributor
Posts: 145
Joined: Sun Feb 01, 2004 7:12 pm
Location: New York City

Post by no_memories »

Thanks for the info.

I do follow what you are saying, lol, but here is the 99 million $$$ question.

I'm not sure how to write the actual link that would reach out to the article directory.

example link: <p>blah blah blah blah blah blah <a href="$filename = "path/to/articals/artical_".$_GET[getid].".php"">article01.php</a> blah blah blah blah blah blah</p>

I'm guessing the php value for the link would need to have some identifier for the output page?

example output on template page: <div id="artclop"><?php echo $_POST["articleoutput"]; ?></div>

I'm guessing this would be the proper way of accomplishing something like this?

I already have something similar now with certain content. An example would be: <div><?php require("content/index-pi.php"); ?></div> But this doesn't require a link to post the results on another template page. It simply grabs the given page and posts it within the same document.

BTW, here is the site I want to incorporate this with - a tableless xhtml site. http://www.thexvector.us/
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

Some pseudo-code for the container page:

Code: Select all

<?
      $article = $_GET['article'];
?>

<head />
<body>
<? 
     include_once $article . ".php" 
?>
</body>
To navigate to another article:

<a href="articles.php?article=$someArticleName">click for an article</a>

That's really all there is to it. Of course, then you need to have a separate .php (or whatever) file for each article. Depending on the size of your site, an even better way might be to hold them all in an array(?) or database.
User avatar
no_memories
Forum Contributor
Posts: 145
Joined: Sun Feb 01, 2004 7:12 pm
Location: New York City

Post by no_memories »

Thanx a bunch,

I'll experiment and post the results here later this week. I'm still working on a nice complimentary template right now.

8)
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Check variables first and hard code in as much info as possible i.e. the path/to/articals/artical_ or else somebody could easily exploit the script and view any file on your server.
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

yeah, should have mentioned that. big omission.
Post Reply