Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 4 123 ... LastLast
Results 1 to 15 of 47
  1. #1
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts

    Include and Perl script help

    Hi

    I use this on the few remaining html pages I use
    <!--#include virtual="/do-this.php"-->

    I have been trying to include (run this) from within
    a perl script, I must have tried a million ways so far

    One quick example being

    $do_file = "do-this.php";
    print "Content-type: text/html\n\n"; open(FILE,"$do_file"); while() { print $_; } exit;

    the only way I can get this to work so far, is via JS, or a image
    tag, which does not work in all cases and of course does
    not work for search engines.

    I'm looking for a solution that will do the same thing as this
    <!--#include virtual="/do-this.php"--> does on html pages if possible,
    if there is no way to do this can someone confirm this and I will give
    up on this.

    This is one of my favorite scripts it has never given me a problem in
    over 8 years, I would hate to have to use a php version of it.

    Thanks
    Sonny

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,874
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Is this what you're looking for?
    Code:
    my $php_output = `/do-this.php`;
    
    print "Content-type: text/html\n\n";
    
    print $php_output;

  • #3
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by FishMonger View Post
    Is this what you're looking for?
    Code:
    my $php_output = `/do-this.php`;
    
    print "Content-type: text/html\n\n";
    
    print $php_output;

    NO

    Make that one million and 1

    Code:
    #!/usr/bin/perl
    
    my $php_output = `/test.php`;
    
    print "Content-type: text/html\n\n";
    
    print <<ENDOFHTML;
    <html><head><title>hello world</title></head>
    <body> <table width="100%">
    <tr><td align='center'>Hello World!</td></tr></table><br />
    ENDOFHTML
    
    print "<font color=green'>bye!</font></body></html>\n";
    print $php_output;
    That does not work as well
    Sonny

  • #4
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,874
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Have you tried swaping these 2 lines?
    Code:
    print "<font color=green'>bye!</font></body></html>\n";
    print $php_output;
    If that doesn't do what you want, then please give more details of what you need.

  • #5
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by FishMonger View Post
    Have you tried swaping these 2 lines?
    Code:
    print "<font color=green'>bye!</font></body></html>\n";
    print $php_output;
    If that doesn't do what you want, then please give more details of what you need.
    OK swapped them and got the same result,
    common You had a feeling it would not work right?

    I have been playing with this for over
    2 months now, I knew it was not that simple.

    I am trying to run and display the follwing
    PHP page within a perl script footer, this
    works fine in html and PHP pages

    PHP Code:
    <?
    require "/home/content/html/connect.php";
    include 
    "/home/content/html/log-insert.php";
    ?>
    <?
    $query
    =" SELECT * FROM visits ORDER BY id DESC LIMIT 5";
    $result=mysql_query($query) or die(mysql_error());
    while(
    $row =mysql_fetch_array($result))
    {

    $flag=$row['flag'];
    $country=$row['country'];

    echo 
    " <b>$country)</b> &nbsp;<img src='/images/flags/$flag.png' width=18 height=12>";
    echo 
    "<br>";
    }
    ?>

  • #6
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    what error message are you getting, either in your script or server errors log?

    At a guess (at 3am), you may need to start with putting your <? .... php tags inside a print statement. Likely you'll need to try other things as well.

    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #7
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by bazz View Post
    what error message are you getting, either in your script or server errors log?

    At a guess (at 3am), you may need to start with putting your <? .... php tags inside a print statement. Likely you'll need to try other things as well.

    bazz
    No what?

    You may be on to something
    Its a mere 10.12pm here, and I am calling it a night
    I will try that tomorrow and post back

    Thank you for weighing in on this
    Sonny

  • #8
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,874
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Telling us that it doesn't work or that you get the same result without telling us what that result was is meaningless to us.

    What output did you get?
    How did that output differ from what you expected?
    What, if any, was the error in the web server error log?
    Do you have warnings enabled?
    Are you directing the errors and warnings to the browser?

    If you're not doing anything "special" in the php script that Perl can't handle, which is extremely unlikely, then the best solution is to drop the php script and do everything it does directly in the Perl script.

    You should do that db call in Perl rather than php.
    DBI - http://search.cpan.org/~timb/DBI-1.609/DBI.pm

  • #9
    Senior Coder
    Join Date
    Mar 2006
    Posts
    1,274
    Thanks
    2
    Thanked 39 Times in 38 Posts
    I would be a little surprised if this works:

    my $php_output = `/test.php`;

    that seems like it would need to fetch a webpage, which I am not sure the above would do.

  • #10
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by FishMonger View Post
    Telling us that it doesn't work or that you get the same result without telling us what that result was is meaningless to us.

    What output did you get?
    How did that output differ from what you expected?
    What, if any, was the error in the web server error log?
    Do you have warnings enabled?
    Are you directing the errors and warnings to the browser?

    If you're not doing anything "special" in the php script that Perl can't handle, which is extremely unlikely, then the best solution is to drop the php script and do everything it does directly in the Perl script.

    You should do that db call in Perl rather than php.
    DBI - http://search.cpan.org/~timb/DBI-1.609/DBI.pm
    I thought I was very clear in my first post, if not sorry

    I can tell you for sure, I am not trying to run the world with that php
    include for testing purposes, I am simple trying to include a php page

    So for testing sake, lets keep things very simple
    Below is the test Perl script

    Code:
    #!/usr/bin/perl
    
    my $php_output = `test.php`;
    
    print "Content-type: text/html\n\n";
    
    print <<ENDOFHTML;
    <html><head><title>hello</title></head>
    <body> <table width="100%">
    <tr><td align='center'><h2>Hello this is a Test</h2></td></tr></table><br />
    ENDOFHTML
    
    print "$php_output";
    print "<center><h3><b>my php include should display directly Above in Red text</h3></center></b></body></html>\n";
    Below is the test Php page I would like to include in that Perl script above
    PHP Code:
    <html>
    <head>
    <body>
    <?PHP
    print '<h2><font color=ff0000><center>I am a php include</h2></center></font>';
    ?>
    </body>
    </html>
    My expectation is to see the php include text when I call that perl script

    Sonny
    Last edited by sonny; 08-03-2009 at 04:43 PM. Reason: correct spelling errors

  • #11
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,874
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Execute the php script by executing the php interpreter and pass the script as its parameter and don't print the headers in the php script because that will give you 2 sets of headers, which you don't want.

    Try this:
    test.php
    Code:
    <?PHP
    print '<h2><center>I am working relax!<br>Yours truely PHP include</h2></center>';
    ?>
    test.pl
    Code:
    #!/usr/bin/perl
    
    my $php_output = `php test.php`;
    
    print "Content-type: text/html\n\n";
    
    print <<ENDOFHTML;
    <html><head><title>hello</title></head>
    <body> <table width="100%">
    <tr><td align='center'><h2>Hello this is a Test</h2></td></tr></table><br />
    ENDOFHTML
    
    print "$php_output";
    print "<center><h3><b><font color=red>my php include should display directly below in black text</h3></center></font></b></body></html>\n";

  • #12
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,874
    Thanks
    2
    Thanked 164 Times in 159 Posts
    The php script could simple be just 1 line, the print statement.

    [root@fc4dev ~]# cat test.php
    <h2><center>I am working relax!<br>Yours truely PHP include</h2></center>;

    [root@fc4dev ~]# cat test.pl
    #!/usr/bin/perl

    my $php_output = `php test.php`;

    print "Content-type: text/html\n\n";

    print <<ENDOFHTML;
    <html><head><title>hello</title></head>
    <body> <table width="100%">
    <tr><td align='center'><h2>Hello this is a Test</h2></td></tr></table><br />
    ENDOFHTML

    print "$php_output";
    print "<center><h3><b><font color=red>my php include should display directly below in black text</h3></center></font></b></body></html>\n";

    [root@fc4dev ~]# ./test.pl
    Content-type: text/html

    <html><head><title>hello</title></head>
    <body> <table width="100%">
    <tr><td align='center'><h2>Hello this is a Test</h2></td></tr></table><br />
    <h2><center>I am working relax!<br>Yours truely PHP include</h2></center>;

    <center><h3><b><font color=red>my php include should display directly below in black text</h3></center></font></b></body></html>
    Last edited by FishMonger; 08-03-2009 at 04:54 PM.

  • #13
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    No that did not work either, I used the following to test
    Sonny
    Code:
    #!/usr/bin/perl
    
    #test.cgi
    
    my $php_output = `test.php`;
    print "Content-type: text/html\n\n";
    
    print <<ENDOFHTML;
    <html><head><title>Hello</title></head>
    <body> <table width="100%">
    <tr><td align='center'><h2>Hello this is a Test</h2></td></tr></table><br />
    ENDOFHTML
    
    print "$php_output";
    print "<center><h3><b>PHP include should display directly above in red</h3></center></b></body></html>\n";

    PHP Code:
    <?PHP

    //test.php

    print '<h2><b><fon color=FF0000><center>I am working relax!<br>Yours truely PHP include</h2></b></font></center>';
    ?>

  • #14
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,874
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Did you try what I suggested?

    Code:
    my $php_output = `php test.php`;

  • #15
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by FishMonger View Post
    Did you try what I suggested?

    Code:
    my $php_output = `php test.php`;

    Yes that did not work as well
    Code:
    $php_output = `*php* test.php`;
    Sonny


  •  
    Page 1 of 4 123 ... LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •