homepage Welcome to WebmasterWorld Guest from 54.145.183.126
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
Dynamic Site Design Question
Getting Perl or PHP in the middle of a page? (Warning: Newbie)
cjthibeault

5+ Year Member



 
Msg#: 3369 posted 1:25 pm on Dec 15, 2003 (gmt 0)

Hello Everyone.

First time poster, long time lurker. I'd like to redesign my site to make it easier for me to make site-wide changes, and I am in need of some basic information.

In my experimenting, I have found that Javascript suits my needs well, but it is obviously bad for SEO. I'm looking at doing something server side with either Perl or PHP, but I am not quite sure how to go about getting things to work the way I want.

What I have right now is an HTML page that has hard coded table layouts, and numerous calls to an external Javascript file. The calls are mostly to functions that do document.write type stuff. The end result is that the content is written in the middle of my existing HTML page.

I'd like to do similar in Perl or PHP, but all the examples and tutorials I have found so far involve replacing my HTML file with .pl or .php file that writes out the page in full. Surely there must be a way to get bits and pieces inserted in the middle of an already existing HTML page? Sort of like an include file or something similar? An example of the Javascript I'd like duplicate is:

In my HTML code:
<script type="text/JavaScript" language="JavaScript">
WriteMainLeftNav();
</script>

In my Javascript:
function WriteMainLeftNav()
{
document.write("tags and content") ;
etc...
}

If someone could suggest a way to duplicate this in Perl, PHP, or some other server-side method while retaining the two-file format (HTML + external code file), it would be very much appreciated. I'm running on Apache 1.3.29 on a linux box. If there is any special configuration information I might need to get it running, that would also be helpful.

PS. I'm primarily a C++/VB guy, and server-side web stuff is not my strong area. Please be gentle :)

 

sugarkane

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3369 posted 1:52 pm on Dec 15, 2003 (gmt 0)

Hi cjthibeault and welcome to WebmasterWorld

You can do this in both Perl and PHP. I think that the PHP way of doing things is perhaps more conceptually similar to the way you're doing things now. Instead of including <script> tags in your html, you'd use something like this:

<?
include("yourincludefile.php");
?>

where yourincludefile.php contains the code to generate whatever dynamic content you want.

You'd also have to change your .html file to .php, unless you add a line to your .htaccess file to parse .html pages for PHP:

AddType application/x-httpd-php .html

On it's own, Perl turns the concept on it's head - you generally build a dynamic page and include any static html either by a simple print command, or using 'require' to pull it in from an external file. If you wanted to use Perl, your situation would probably be best dealt with by a combination of Perl and Server Side Includes (SSI). Again, instead of the script tags, you'd use:

<!--#include virtual="/cgi-bin/yourscript.pl" -->

where yourscript.pl generated the dynamic stuff.

Again, you'd have to modify your .htaccess file to tell the server to parse for SSI

AddHandler server-parsed .html

Storyteller

10+ Year Member



 
Msg#: 3369 posted 9:51 pm on Dec 16, 2003 (gmt 0)

cjthibeault, for a newbie it may even be a good idea to start playing wtih not PHP or Perl, but with plain SSI. It's minimal and easy to use, but is sufficient for many basic needs.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved