Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 24th, 2001, 12:04 PM
WarpOne WarpOne is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 0 WarpOne User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question

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!

Reply With Quote
  #2  
Old April 24th, 2001, 04:49 PM
unobserved unobserved is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 11 unobserved User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to unobserved
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";

Reply With Quote
  #3  
Old April 29th, 2001, 10:17 PM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 10
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.

Reply With Quote
  #4  
Old April 30th, 2001, 11:31 AM
Atrus's Avatar
Atrus Atrus is offline
yet another member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 262 Atrus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
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.

Reply With Quote
  #5  
Old April 30th, 2001, 11:49 AM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 10
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 )

Reply With Quote
  #6  
Old May 7th, 2001, 10:35 AM
moyashi moyashi is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 4 moyashi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #7  
Old May 17th, 2001, 01:21 PM
pgazmuri pgazmuri is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: Burlington, VT
Posts: 1 pgazmuri User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > including PHP page (header/footer) from a CGI script?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT