Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
February 09, 2012, 06:44:47 PM

Pages: [1]   Go Down
  Print  
Author Topic: PHP parse for one page only?  (Read 1792 times)
webweaver
Galactic Royalty
*****
Offline Offline

Posts: 206


WWW
« on: November 28, 2009, 08:12:18 PM »

I use SSI includes for my web site and parse the pages as shtml.  I have one page that I would like to include my most current wordpress blog posts and have a little tutorial on how to do that.  But the page has to either be named pagename.php or the page must be parsed as php. I want to continue the  pagename.html but parse as php but I also want my "includes" to work.  I have not been able to get a test page to parse both as shtml and php.  I guess I should learn how to do php includes and will work toward that on my site, but for now my questions are:

1.  Is there a way to parse for both shtml and php?  I have tried various additions to my htaccess file to accomplish that but so far if it reads the php it will not read the ssi includes and vice versa.

2. IF NOT, can I put a line in my htaccess to parse just one specific page as PHP?  This will allow me to learn how to do my includes on this one page with php - seems daunting but maybe can get some guidance on that - and will allow me to get the PHP content into that page that I want without having to edit all my pages includes statements. So far I only need the php on this one page.

3. Does using php to include content in my page make my page any more vulnerable to hackers and/or exploits?  I would rather do without the content than be vulnerable.

Thanks for any help you can give. 

My site is http://weavehouston.org/ 

However I think when you "View Source" it shows the included content already on the page.  The items I now have included are my left navigation bar and the right bar and the footer. Right now when i want to include a file I just use this:
<!--#include file="filename.html"--> and since my html files are parsed as shtml, it works. 

Webweaver

Logged
MrPhil
Berserker Poster
*****
Offline Offline

Posts: 5083



« Reply #1 on: November 29, 2009, 05:47:31 AM »

1. I don't know of any way to both parse SHTML and PHP. AFAIK it has to be one or the other. You should be able to use PHP's include on an .html file, eliminating the need to do SSI codes.

2. I would think that you could name your page blogpage.php (the physical file). Link to it as blogpage.html (looking like any other page). In .htaccess, URL rewrite it to rename from blogpage.html to blogpage.php. I can't see why that wouldn't work.

3. PHP is vulnerable only if you accept user input and you fail to properly validate it (screen out various "injection" attacks). There's nothing intrinsically vulnerable about PHP, but there are subtle ways that hackers can get in with user input, if you're not careful. Don't forget to screen (validate) any URL Query String or form input and don't use register global variables for passing UQS or form data.
Logged

wektech
Master Jedi
*****
Offline Offline

Posts: 1031



WWW
« Reply #2 on: November 29, 2009, 06:35:23 AM »

You could write the php page to return the only the content you want keeping the php extension and then use an ssi include to pull that file.
Logged

webweaver
Galactic Royalty
*****
Offline Offline

Posts: 206


WWW
« Reply #3 on: December 01, 2009, 02:27:02 PM »

Mr. Phil and Wektech,

Thanks for your comments.  I think I am going to redo just that one page and its "includes" as php and see if I can make my project work.

It may take me some time.  I will post again when (if?) I get it all working and tell you how I did it.

Webweaver
Logged
webweaver
Galactic Royalty
*****
Offline Offline

Posts: 206


WWW
« Reply #4 on: December 01, 2009, 08:24:32 PM »

Ok, if anyone interested, here is what I have learned:

I created a php page modeled on my existing index page.

At the very top of the page (following instructions from corvidworks from October 2008 on displaying wordpress content outside your blog) I put:

<?php
//Include Wordpress
define('WP_USE_THEMES', false);
require('./blog/wp-blog-header.php');
query_posts('showposts=6');
?>

Then on the page I where I wanted the blog posts to appear, I put:

<?php while (have_posts()): the_post(); ?>
<?php endwhile; ?>
<?php while (have_posts()): the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php endwhile; ?>

I still have a lot of work to do, including deciding whether it is worth it to do this, but you can see what I have done so far on my test file at http://weavehouston.org/wordpressimporttest2.php.

On the "worth it" issue: I know many of our members will never go to the blog for the "news" so I have been duplicating effort putting our news stories on both the blog and the main page.

On my web site I have html files that are ssi includes as my menus on the left and right and a footer at the bottom.

To bring them into my test file, I used the PHP include statement using this syntax:

<?php include("filenameleft.html"); ?>
<?php include("filenameright.html"); ?>

[I thought I would have to save these included files with the php extension but they work with the html extension.]

On my right menu file, it already had an ssi include for the meeting information so I ADDED a php include to it. This makes the same included file work on both my php page AND my html pages. Is it kosher to have both a php and an ssi include calling the same file?  I do that so I do not have to have separate menu files for my php page and my html page.

Issues:  1. Right now I have NOT changed my top item on my left menu included file to point to the index.php because I am just testing and so far do not have index.php.  

2. I cannot get the date updated to return at the bottom of my php page.  I am sure I need a PHP statement to accomplish that, but the one I tried did not work.

3.  I pride myself on validating my pages but the entries pulled in from the blog don't validate.  I have not closely examined this to see if it is because of my errors when posting to the blog or some other issue.

Anyway, I am happy to have accomplished a web page pulling in blog posts for now!!! Go look at it at http://weavehouston.org/wordpressimporttest2.php - UPDATE: the file I was working on is now called index.php - and give me the benefit of your feedback.

Webweaver



« Last Edit: December 02, 2009, 08:21:56 PM by webweaver » Logged
Danielle
Guest
« Reply #5 on: December 01, 2009, 10:06:50 PM »

It looks pretty good. I really don't have anything to say about it beyond that for any suggestions for improvement. Good job Webweaver 2 Thumbs Up
Logged
webweaver
Galactic Royalty
*****
Offline Offline

Posts: 206


WWW
« Reply #6 on: December 02, 2009, 07:43:42 AM »

Tristan,

Thanks! 

As an update,

On issue #1 about changing my menu to point to index.php, I think I will follow Mr. Phil's advice when I reach that stage and use the htaccess file to rewrite to the index.php.

 Issue #2 solved - I have resolved the date/timestamp issue thanks to some code on some page somewhere.  Smile).

Here's the code I found:
<?
$last_modified = filemtime("filename.php");
print("Last Modified ");
print(date("m/j/y h:i", $last_modified));
?>

 Issue #3: Still haven't examined my validation issues as to whether they are my carelessness in writing my original blog posts or because of the way they are formatted by wordpress.  If the latter,  I can live without one page validating purely.

I love this stuff.

Webweaver

Logged
webweaver
Galactic Royalty
*****
Offline Offline

Posts: 206


WWW
« Reply #7 on: December 02, 2009, 08:18:10 PM »

And to wrap it all up, I have completed my project and solved all my outstanding "issues".  Now my main page for the website is index.php and pulls in my 5 most recent blog entries, my html include files, and validates.  If someone has the site bookmarked as http://weavehouston.org/index.html it goes to the root which brings up the index.php.

If anyone sees any issues with the site, please let me know.

Thanks for everybody's help and all the good information on the Lunar Forums!

Webweaver



Logged
MrPhil
Berserker Poster
*****
Offline Offline

Posts: 5083



« Reply #8 on: December 03, 2009, 01:54:33 PM »

You gave the following code example:
Code:
<?php while (have_posts()): the_post(); ?>
<?php endwhile; ?>
<?php while (have_posts()): the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php endwhile; ?>

You could do a lot less typing and have clearer code with:
Code:
<?php 
while (have_posts()) the_post();
while (
have_posts()) {
  
the_post();
  echo 
'<h2>';
  
the_title();
  echo 
'</h2>';
  
the_content(); 
}
?>

I don't know what the_post() does, so I can't tell you if you don't need it twice.
Logged

webweaver
Galactic Royalty
*****
Offline Offline

Posts: 206


WWW
« Reply #9 on: December 03, 2009, 03:13:52 PM »

Mr. Phil,

Yes I noticed the duplication this morning and took out these 2 intial lines:

<?php while (have_posts()): the_post(); ?>
<?php endwhile; ?>.

I was copying and not thinking when I put in those lines. The article I was using was very clear and going step by step, but I took it too literally.  I know nothing about php, but when I reviewed it as I was documenting what I had done for my own records, I realized that those 2 lines were duplicates.

Thanks for the clearer code.  You can tell I am just a monkey copying it all right now, but I think as I tinker with php and read some web articles and some books, it will become more understandable to me.

I'm off to use your clearer and more efficient code with the exclusion of the first line while (have_posts()) the_post();.  I am using echo as you showed and have decided to use <p>'s instead of the <h2> because i had to do some not very nice things in my css to make these <h2>'s look more like I wanted them to.  I just completely overlooked that the <h2>'s were coming from these lines.  For some reason I thought they were pulling in with the the_title even though it was staring me in the face right there! DUH.

So this is the code I ended up with:

<?php
while (have_posts()) {
  the_post();
  echo '<p><strong>';
  the_title();
  echo '</p></strong>';
echo </strong></p>;
  the_content();
}
?>

THANKS so much for your help!

Webweaver



« Last Edit: December 07, 2009, 06:00:47 PM by webweaver » Logged
Pages: [1]   Go Up
  Print  
 
Jump to: