|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
is this possible.. to call a php page from a CGI script?
like: <? virtual ("/banner.php"); ?> <? include ("http://www.warp.f2s.com/banner.php"); ?> what be the "include" for a cgi script..to call a php page Thanks! |
|
#2
|
|||
|
|||
|
this should work fine:
Code:
print "Content-type: text/html\n\n";
print '<? virtual ("/banner.php"); ?>';
print "\n\n";
print '<? include ("http://www.warp.f2s.com/banner.php"); ?>';
print "\n\n";
|
|
#3
|
|||
|
|||
|
No, that wont work at all. <? ?> stuff is actually processed by the webserver and php, not the client browser. The best way to do it is:
Code:
use LWP::Simple;
$php_data = get('http://www.blah.com/page.php');
print $php_data;
This will grab the page via the http method and return whatever it would return if you were calling it via your browser. |
|
#4
|
||||
|
||||
|
Hi!
I must add that unobserved is partly right on this, though. Depending on your apache configuration you may have perl output parsed for php <? ?>. See thread 13995 on how Captain Proton has to struggle with that ![]() Greetings Atrus. |
|
#5
|
|||
|
|||
|
No you can't... perl itself isn't even parsed (well compiled and executed in perl's case) at the apache level. As far as I can tell, this thread is talking about putting it in an html file, which is parsed by apache.
Well, that is to say that I'm 99.99999999% sure . Just don't see how it would be possiable without really hacking the perl source code and doing something with mod_perl.(didn't mean to sound like an *** in the pre-edit post ) |
|
#6
|
|||
|
|||
|
that's awesome ....
JonLed,
your solution is just awesome. Great .... that little trick with simple.pm that have libwww installed on their hosts. This will help a lot of people out who want to move to a php script yet maintain their original perl scripts. NOTE: I don't know the security of this SO don't blame me .... for those of you who have a D_CK for a system engineer on your host, try this, once again I don't know the security or danger of this solution to add libwww to your own cgi-bin. On my main host the system engineer refused to allow LWP.pm to be installed at root level. I went through hell figuring this out but try it and don't blame me .... 1.) go to URL and just download the file ;-) 2.) untar it / unzip it, what ever just open it ;-) 3.) upload to the folder that has the cgi that is causing you troubles. Or in my case was the folder that need the php script to be called. There is a way to clean this up but I forgot since it was about a year ago that I figured this out. note: .... I pull the files and folders out from libwww and just upload them 1 by 1, some seem to need the other so just LWP and LWP.pm aren't enough, I put up everything except the first folder (holder) contents all are uploaded. I'm sure a good hacker could figure this out but then again my ISP was just killing me with the denial of SSIs and LWP ;-) 4.) use JonLed's solution of course call your file. 5.) If this is wrong or can be expanded upon please feel free... good luck and thanks for the help, well indirectly. |
|
#7
|
|||
|
|||
|
if the 'get' method doesn't work, you can always do it the hard way:
use Socket; #keep this line at the begining of your script $host = 'www.yourhost.com'; $page = 'directory/yourfile.php'; $in_addr = inet_aton($host); $port = 80; $addr = sockaddr_in( $port, $in_addr ); $proto = getprotobyname( 'tcp' ); # Create an Internet protocol socket. socket( SOCK, AF_INET, SOCK_STREAM, $proto ) or die "socket:$!"; # Connect our socket to the server socket. connect( SOCK, $addr ) or die "connect:$!"; # For fflush on socket file handle after every # write. select(SOCK); $| = 1; select(STDOUT); # Send get request to server. $req="GET /$page HTTP/1.0\nHost: $host\n\n"; print SOCK $req; $str=''; while($response=<SOCK>){ $str.=$response;} $i= index($str, "\r\n\r\n");#get offset $fstr=substr($str, $i); print $fstr; close(SOCK); it's messy, but it works! this snippet of perl will output whatever URL outputs! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > including PHP page (header/footer) from a CGI script? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|