Implementing PHP: server to PHP interface?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Danielh
Forum Newbie
Posts: 4
Joined: Sat Jul 19, 2003 8:03 am

Implementing PHP: server to PHP interface?

Post by Danielh »

I'm the author of sre2003-srehttp/2, a freeware web server for
OS/2. A user of this product has asked me about supporting PHP.
I've located a standalone version of PHP for OS/2.

[Did I mention that I've never used PHP before??]

My simple experiments worked (i.e.; hello world).

My question is how to provide PHP with the various and sundry variables
it expects. Such as those required by
<?php echo $_SERVER["HTTP_USER_AGENT"]; ?>
<?php echo $_POST["name"]; ?>.
<?php echo $_POST["age"]; ?> years old.


I was able to resolve the $_SERVER["HTTP_USER_AGENT"] by creating a
HTTP_USER_AGENT variable in the environment -- in fashion similar
to how CGI-BIN scripts expect to lookup such server data.

This leads me to believe that PHP uses a similar technique for obtaining
other variables (such as the $_POST and COOKIE variables). But perhaps not
(especially for FILE uploads!)

So, my question(s) is:
How does PHP expect to recieve the variables it is supposed to support?
Is there some simple documentation that explains this?

Thanks.
jollyjumper
Forum Contributor
Posts: 107
Joined: Sat Jan 25, 2003 11:03 am

Post by jollyjumper »

Hi Daniel,

At http://www.php.net/download-docs.php you can find documentation about php in different formats.

Search for global variables to see the list of all the available $_ variables. And yes you were right with $_POST for catching posted data.

Greetz Jolly.
Danielh
Forum Newbie
Posts: 4
Joined: Sat Jul 19, 2003 8:03 am

Post by Danielh »

Um, the manual is huge, so even after an hour or so, I could not find any documentation explaining the interface between a "server" and "PHP".

And , um... but... I figured out how to do $_SERVER ..., but have NO idea
how to do $_POST, etc.

So, if anyone could point me to the SPECIFIC chapter detailing just how
PHP retrieves this sort of information (i.e..; how it reads $_GET(..)) I would be
much appreciative.


(i'm wondering if it's just the same as CGI, I'll have to experiment...)
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post by Cruzado_Mainfrm »

in the php manual, the first 3 chapters are the only that will tell u how is the php programming at a basic level, after that the Functions Reference part of the php manual is ought to be read so u can understand the 'chemistry' of php, by that i mean, that u have to know how functions work, how to use them etc etc...

answering the last question, u can see all the data stored in the variables:
$_GET, $_POST, $_COOKIE, AND $_SERVER use the function:
print_r ($_GET);
print_r ($_POST);
print_r ($_COOKIE);
print_r ($_SERVER);
u might want to add the tags <pre> and </pre> and put the function in between so u can understand it better...
the $_GET variable contains the data passed in the URL, ex.:
http://mysite.com/mypage.php?myvariable=its_value
i can access 'myvariable' by two methods(the only two i know for now :mrgreen:):
$_GET['myvariable'] which is case sensitive and $myvariable which i don't know if is case sensitive...
try echoing like this:
echo $_GET['myvariable'];

for $_POST variables this is another example, create a file called mypage.php and put this into it:

Code: Select all

<form method="POST" action="mypage.php">
<input type="text" name="myvariable" value="">
<input type="submit" value="Send variable">
</form>

<?php
echo $_POST['myvariable']; //case-sensitive
echo $myvariable;
//BOTH WILL PRINT THE SAME THING
?>
u can see the server variable at a glance using the function:

Code: Select all

<?php
phpinfo();
?>
to set a cookie u go like this
$seconds = 3600; //1 hour
setcookie("mycookie","value",time()+$seconds); //the other last two things i dunno how to use them, sorry

to delete the cookie just go minus :D
setcookie("mycookie","value",time()-1);

if u want a cookie that will only delete when u close the browser:
setcookie("mycookie","value");

to access this cookie use:
echo $_COOKIE['mycookie'];

hope this helps
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Danielh is asking how to allow a new webserver to invoke PHP and pass the appropriate values to PHP, NOT how to use those variables from within PHP.

I would suggest checking the source for PHP, I know when i looked at it a few years ago there were directories for apache and sapi and other interfaces. Seeing what they do there should help you know what the executable expects, and includes the build process for the mod_php library used by the webserver.

Further I would suggest contacting one of the PHP mailing lists, possibly even the php-internals list in order to get to people who develop PHP rather than developers who use PHP (the majority of people on this board only use PHP, not develop it.)
Danielh
Forum Newbie
Posts: 4
Joined: Sat Jul 19, 2003 8:03 am

Post by Danielh »

Thanks, Cruzado, for the long reply, but Nielsene has it right :> - - I can
invoke PHP (in a seperate process), but I need to know just how to pass
(to this process) the variables, etc that PHP uses .

As for checking the source..... ugh, t was hoping to avoid that (esp. since
I don't write in C).

I'll try the internals mailing list, but if anyone reading this thread can help out,
I'll keep checking back.
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post by Cruzado_Mainfrm »

yup i wasted my time...
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

If the PHP binary you found for OS/2 is an executable it is likely to be the CGI version? and it would expect post at STDIN, just as with any other cgi interface.. I dont know if GET comes in that way or if PHP just extracts it from the query string in ENV(?), I never studied this, I would think that looking at the CGI specs (for e.g. apache) would be more useful?
Danielh
Forum Newbie
Posts: 4
Joined: Sat Jul 19, 2003 8:03 am

Post by Danielh »

My guess is that it is a "CGI" version, which I take to mean that it reads
variables in the same way that a CGI script (say, one written in PERL) would
read them.

Since my server DOES currently support CGI, it's only a matter of tedium to
tweak my server to use PHP as if it were a standard cgi-bin request. Perhaps
it can't be avoided.

BTW: Cruzado, your post is not wasted - I can use it to make a
test script for testing to see whether my php interfact is working!
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post by Cruzado_Mainfrm »

if u say so :mrgreen:
Post Reply