[prog] Calling a perl program from within PHP
Gareth Anderson
somecsstudent at gmail.com
Sat Nov 13 13:38:53 EST 2004
Hi,
> > Cannot have a .htaccess file (which would easily do the
> > authentication) in a cgi-bin directory.
>
> This is not strictly true. However it may be true -in your case- if > your system administrator has set:
>
> Allow Override = 0
>
> in the Apache config. You might get somewhere by asking them nicely if
> they could please allow you to have .htaccess files in *your* cgi-bin.
I seriously doubt I could convince a university to make changes to a
single account for myself.
> > Cannot have a cgi script outside the cgi-bin directory (but can have > > .htaccess outside there).
>
> Yup. Although once again, this is configurable.
Yes, monash's configuration is locked down, no POST method to stuff
not in cgi-bin and GET method does not work outside cgi-bin.
> > Cgi-wrap removes what I'm trying to get (the username).
What I mean is that cgi-wrap will run the program as myself.
There goes the REMOTE_USER even if I could get to it.
> You could do form-based + cookies authentication. This is usually nicer > than .htaccess and has the advantage that if your site is accessed at a > public workstation then failure to close down the browser does not
> *necessarily* mean that identity spoofing can occur.
I've got no idea how to do cookies.
I'd rather rely on authcate, its sorta simpler...(once I do get PHP),
and I want it restricted to monash-only.
> Hmm. Perl can use Java libraries and Python libraries and Ruby > libraries (plus many more). Many of those languages can use Perl > libraries too. However, Perl and PHP don't mix as well together.
Damn :(
> The problem is that the cgi program expects a certain setup including a > host of environment variables, input on STDIN and STDOUT to be the > webpage. Calling one from the other is therefore necessarily ugly.
Yes, thats what I was afraid of.
> Having said that, it's easier to call Perl this way from PHP than the > reverse. I'd do something like:
>
> <?
> /* Set up any extra environment bits */
> system('/usr/bin/perl myprogramname');
>
> /* Do anything that needs doing */
> ?>
>
> Having said all of that, If your PHP script can work, I'd be seriously > wondering why your Perl script cannot. It means one of the enviroments > is probably badly setup.
Yes, yoyo the student run server is said to have broken CGI for now
but PHP is still working.
> Yes, you could do that.
I might :)
> It'll need to be executable by the process which runs the PHP script, or > you need to make it readable by this process and then execute it by > calling the interpretor.
Yes...
> Calling system should (please double-check) fork such that the new > process's STDOUT goes to your original STDOUT which should achieve what > you want.
A quick read has me confused :).
I know the C version does do this, I guess I will have to try it when
I do get PHP access...
http://au.php.net/manual/en/function.system.php
> Yes that would probably work as well. And if you don't need anything > else done after you call the Perl program then exec is probably better.
Oh ok, I'll try both then. The perl program will be the last thing.
> Heh. I can see that with your username, you could hit that assumption.
:)
Well exams are over, I'm on holiday.
I've already being accused of abuse of staff privileges for discussing
this with monash's technical staff (from my staff account at monash).
>
> All the best,
Thankyou, if all else fails I''ll re-write it in PHP.
The only hard thing is the persistent array can't exist in PHP :(.
It was suggested this:
$usernames = file('usernames.txt');
I could do that with some dodgy programming (ie. messy but it will work).
Does PHP have anything close to a dictionary/associative array/hash
that can be written and read from disk easily?
Regards,
Gareth
More information about the Programming
mailing list