pmaes3 has asked for the wisdom of the Perl Monks concerning the following question:

Hello!

I'm familiar with perl, but not with php.

For a new online application of our institute, I made an cgi script. But for the lay-out, I must use certain CSS files that are made available on a general server of the institute.

Now I have to include following php-code in the header of the html-file. I tried several things, but nothing seems to work:

This is the php-code that must be included in the header:

---
<?php include("http://stijl.kuleuven.be/includes/styles1.inc");?>

<?php if (false) { ?>
<link rel="stylesheet" type="text/css" href="http://stijl.kuleuven.be/_c/main.css" media="all" />
<link rel="stylesheet" type="text/css" href="http://stijl.kuleuven.be/_c/subnav.css" media="all" />
<link rel="stylesheet" type="text/css" href="http://stijl.kuleuven.be/_c/nieuws.css" media="all" />
<?php } ?>
---

In my CGI script, the header is build with start_html(). But I really don't know a way to include the above php-code in the header.

Does somebody may have a solution?

regards,
Piet.

Replies are listed 'Best First'.
Re: How to include php-code in header
by nefigah (Monk) on Apr 01, 2008 at 01:16 UTC

    All the include() function does in PHP is essentially put the contents of whatever referenced file into the current file. Since "styles1.inc" doesn't even have a php extension, I imagine you could do this in Perl (maybe by just opening the file and printing its contents).

    Also, note that your stylesheet links are never going to print, since you wrapped them in if (false) :)

    Update: I imagine they must be wrapped like that so that they will get printed if the code is executed by something not-PHP; it has the look of "yet another crazy html hack" about it.


    I'm a peripheral visionary... I can see into the future, but just way off to the side.

Re: How to include php-code in header
by holli (Abbot) on Apr 01, 2008 at 03:03 UTC
    Straight from the docs:
    CREATING THE HTML DOCUMENT HEADER print start_html( -title=>'Secrets of the Pyramids', -author=>'fred@capricorn.org', -'src'=>'/styles/style1.css'}, -BGCOLOR=>'blue' );


    holli

    The only sane way to cope with terrorism is to ignore it entirely.
Re: How to include php-code in header
by ww (Archbishop) on Mar 31, 2008 at 23:56 UTC
    Why do you have to use PHP?

    I see nothing in what you posted that can't be done with Perl and CGI. Is there some local condition that makes that unacceptable?

Re: How to include php-code in header
by harsha.reddy (Acolyte) on Apr 01, 2008 at 05:32 UTC

    From what you have said I understand that you are calling php code inside perl code. (correct me if I am wrong).
    If yes, then I hope that following URLs may help you:
    http://search.cpan.org/~esummers/PHP-Include-0.2/lib/PHP/Include.pm
    http://search.cpan.org/~karasik/PHP-0.11/PHP.pm
    http://search.cpan.org/search?query=php&mode=all

Re: How to include php-code in header
by dwm042 (Priest) on Apr 01, 2008 at 13:21 UTC
    One good suggestion is that of nefigah, who suggests using Perl to do the same things as the PHP does. Now, if that's not an option, then another is to convert your application to one that uses templates, such as HTML::Template or the Template Toolkit. Then the PHP code would reside in the template itself and your Perl can just add the dynamic content to the template in use.