Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Include/execute PHP header/footer 1

Status
Not open for further replies.

Zhris

Programmer
Aug 5, 2008
254
GB
Hello,

I have been stuck on this one for a few days and have put off posting a thread until I was satisfied I had exhausted all attempts to get this to work.

I have a perl script (script.pl). In a separate folder I have header.php and footer.php. Note that header.php also includes 2 other php files and also another perl file. I simply want to print the output of header at the top of script.pl and the output of footer at the bottom of script.pl.

I have tried numerous methods but keep coming back to this one:

Code:
my $path = getcwd();
my $header = `usr/bin/php -q $path/Header.php`;
print $header;

This pretty much prints the unexecuted contents of the perl script i'm running the code from.

This does nearly what I want:

Code:
my $path = getcwd();
my $header = `lynx -source $path/Header.php`;
print $header;

However it prints "nearly" everything in the sourcecode, but the stylesheet, javascript etc is never picked up.

I have even tried using a php method (print header, execute perl script, print footer) which works great however the perl script requires param data and I have had issues passing the data from the php script to the perl script (either passing the variables through a url OR passing arguements using exec).

How can I print header.php and footer.php in my perl script? I have found tonnes of information across the web, however nothing seems to work for me.

Thank you,

Chris
 
If the PHP script sets the environment variable QUERY_STRING before executing the Perl script, and the Perl script gets its params from the query string, the perl script should be able to get the params.

For example (Perl running Perl):

Code:
# create an enclosing block so we can scope %ENV locally
{
   local %ENV = (
      # whatever environment params you want here
      QUERY_STRING => "hello=world&goodbye=mars",
      REMOTE_ADDR  => "127.0.0.1",
      USER_AGENT   => "Mozilla/4.0 (compatible)",
      #...
   );
   my $out = `perl other-script.pl`;
   print $out;
}

To test:

Code:
# other-script.pl
foreach (keys %ENV) {
   print "$_ => $ENV{$_}\n";
}

Kirsle.net | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
Thats very nice, ill have to give that a go as that was the solution I was aiming for.

I managed to include a header/footer using LWP::Simple 's get() function, however there were conflicting url issues which have created a problem, and it wasn't quite the way I wanted to do it.

If i'm able to pass the params across scripts (as you have examplified in your code above) that would be perfect.

Thank you very much,

Chris
 
I had to run PHP inside CGI/Perl. Most optimal solution was the <ifrme src=xxxx></iframe>. In the PHP script the _GET parms were set which could easily be passed via src link.
 
I try to avoid iframes at all costs. You could have possibly done:

Code:
use LWP::Simple;
my $url = '[URL unfurl="true"]http://www.domain.com/script.php?Field=Value';[/URL]
print get($url);

Kirsle, I managed to implement your script to suit my own requirements and its working great.

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top