[Pmwiki-users] passing variables between php programs

Kass Lloyd raeky
Sat May 15 20:32:54 CDT 2004


> -----Original Message-----
> From: Pmwiki-users-bounces at pmichaud.com [mailto:Pmwiki-users-
> bounces at pmichaud.com] On Behalf Of Crisses
> Sent: Saturday, May 15, 2004 9:58 PM
> 
> > In php you have access to the super global variable $_GET and $_POST
> > that contain all the get and post variables available in the scope
the
> > script is running.
> 
> Yes, but they're in the scope that the script is running.  I can
access
> those.  But how do I pass them to pmwiki.php when I'm ready to call
it?
>   GET implies via URL...how do you supply a URL and POST to send with
> it?

Pmwiki isn't designed to take data from other scripts, at least not
natively. I'm not sure if you can pass it GET variables on an edit page
for content, proably not. You will need to find where in Pmwiki the edit
page is rendered and make it look for a specific GET variable if that
variable exists then just propagate the edit form with that variable
instead.

> 
> >  The website www.php.net is invaluable for command
> > reference in PHP there is so many billions of commands available and
> > even programmers who have been working for many years programming
php
> > can't remember everything.
> 
> Well, that's true, and I've been pouring over the documentation there,
> and unfortunately that doesn't mean it's a good tutorial: it's a
> reference.  it's like *reading* an O'reilly Reference guide [a great
> thing to have on hand but I wouldn't want to start there!] and
> attempting to learn from it (Yipes!).  --Even with a search feature it
> doesn't mean that the functions and code reference equate to a real
> example of what you're trying to do.  So instead of spending more than

Sorry php.net is a good reference for those already familiar with
programming languages and php. If your just learning php this type of
modification to Pmwiki will probably be a difficult task, you will need
to read the code to find out where to make your modifications.

> the several hours I've already done trying to figure this out (between
> that and failed attempts to Google the issue), I figured I'd ask.
None
> of the examples on any of the pages I went through applied -- no user
> comments were helpful -- the documentation was unhelpful.  If someone
> pointed out which functions/methods/whatever would be the right ones
> (or some of the right ones to choose from) in this case, I could look
> them up and see if I could figure it out.  Otherwise, I'm stuck
pouring
> through extensive function lists wondering if there's a module I need
> to load, if it's in the basic documentation, or if I'm simply clueless
> and overlooking something.

There probably several very nicely written introduction to php books on
the market that will help you learn. Or you may consider having someone
else make these modifications for you.

> 
> > This type of application isn't a very hard project, you will have a
> > small form that the user types in whatever they want into a text
field
> > then they hit submit, this calls a php script that parses that form
> > data
> > forms a new url to the Pmwiki (would need modified to accept GET
> > variables to propagate the edit page form), and then just redirects
the
> > user to the new url with get variables. I highly suggest encoding
any
> > user inputted text with base64 before you pass it via a GET
variable.
> 
> I can't tell if what you said is helpful to me where I stand.  I have
a
> working program.  It spits output to a browser in the form of a single
> (imploded array->)string at the end (because it gives me the fun of
not
> having to write a loop, and auto-inserts <br /> breaks between lines).

To add <br /> to the end of every line of a file you can simply use:

str_replace("\n","<br />",$data);

Although depending on the filetype uploaded you may need to search for
other end-of-line characters. But no loops are involved.

http://us3.php.net/manual/en/function.str-replace.php

> I want to know how to pass that array to PmWiki.  I don't think it

To pass a variable, array, or any kind of data via a GET variable you
can simple serialize it then compress and encode that and pass the
resulting string via GET then in the other script you will decode,
decompress then unserialize the variable. 

$var_to_put_in_url = base64_encode(gzcompress(serialize($varable)));
$var_from_string =
unserialize(base64_decode(gzuncompress($_GET['var'])));

http://us3.php.net/manual/en/function.serialize.php
http://us3.php.net/manual/en/function.base64-encode.php
http://us3.php.net/manual/en/function.gzcompress.php

> should be via GET; it's possibly going to get too big.  I need to know
> how to send a POST to another url without using a hidden field on a
> form with a button that necessitates user interaction.  I also want to

I don't believe a url length has a maximum length, it is possible if
your uploading HUGE files. The other option is to send the data via
POST, but post requires the browser to submit the data via a form, this
could be done automatically with javascript but it would make an
intermediate page load up, a "loading" page.

> incur the lowest amount of PmWiki being rewritten.  I'm not sure I
need

Pmwiki probably isn't designed to take data via GET and POST to display
in the edit page form. So this would require a modification, not very
extensive, just a few lines.

> more theory: I actually need someone to point out the command set I
> should study, to hand me a simple line of code (like: "Oh, that's
easy,
> it's blah, I could have told you that; you shouldn't have been banging
> your head against that silly document for 3 hours!"), or to explain to
> me that what I am trying to do isn't possible.  And why, so I can
> reformulate my theories and future plans for this project.

I'm not sure if your wanting this to be done by yourself or if you want
someone else to do it for you? I'm writing my responses in format
presuming that you have at least some experience with php.

> 
> I don't think base64 is going to help (I assume that's for purposes of
> data compression?).  Are you implying the only way to pass variables
> from PHP->PHP is via GET?  Or is it just the easiest way?  You never
> actually said POST is not possible.  What if the text field is so
large
> it's too large for GET even after being encoded in base64?  And what
> library do I find that command (to encode a string in base64) in?

base64_encode doesn't compress, in fact if you encode something via
base64 it usually grows slightly in size. To compress it you would use
gzcompress() before you encoded it. Encoding just makes sure the string
contains only legal characters that can be in a url.

It is possible a huge file compressed this way and passed via a GET
variable could cause problems. In that case you will need to use POST
and some sort of JavaScript to auto submit the post data to the second
script.

There is also php sessions that can be used to hold data. This doesn't
require any GET and POST variables to pass data from page to page. All
it does is sets a cookie on the user's machine and that cookie is read
on each page view and then php looks up the cookie data and then auto
loads up a master array that is the same from page to page.

$_SESSION variable is available once you enable sessions on a page. This
variable works like any other; you can set things in it and read from
it, only this variable becomes available to php script on the site. This
is a feature few utilize in php. I'm not sure on its reliability and if
the user doesn't have cookies enabled I'm not sure it will function.

> 
> > You will proably have to use a piece of compiled software on the
> > machine, here is a link to some solutions for unix to convert a word
> > document into plain text:
> 
> I already have one: Antiword.  I appreciate it though.
> 

Is this a command line program? I merely suggested some programs that
looked pretty powerful and was command line and unix compatible.

> > The php script can call the conversion program and convert the file
as
> > text then read in the text file in then do whatever you want with
it.
> > I'm not sure if Pmwiki will accept page content via a GET variable,
> > proably not. So you proably will need to code a mod for Pmwiki to
take
> > a
> > variable.
> 
> Again: are you saying it's not possible?  Or is it so hard it's not
> worthwhile?

No php can easily execute command line programs and read in files. This
isn't' a very hard task.

http://us3.php.net/manual/en/function.shell-exec.php
http://us3.php.net/manual/en/function.file-get-contents.php

> >
> > header("Location: ".$url);
> 
> Thank you; that part I didn't know.  I can write php but it doesn't
> make me a rocket scientist.  This is the first time (ever) that I'm
> writing a program and want it to interact with another one via the web
> -- although in this case it will reside on the same server (in case
> that changes anything).

Generaly most php scripts must track sessions or variables must be
propgated from page view to page view. This is usually accomplished with
cookies. To send data from one page to another you can either use php
sessions (which uses cookies), or POST and GET data. To send POST you
need to submit a form. To send GET you can just form a url and redirect
the browser to that url.

I'm not sure what the maximum url lengh is for most browsers, but I'm
pretty sure it is quite large. If your dealing with huge files (100k+,
which is HUGE for a text document), then you'll need to use POST as I
talked about above with a javascript submit onPageLoad. 







More information about the pmwiki-users mailing list