Is there a reverse $_GET?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm quite experienced in JavaScript, but needed some PHP to access
plain text data on my server. No sweat to communicate the file name
from JS by the POST/GET method to my PHP snipplet, and to read the text
file contents into a PHP variable $txt.
($txt = fread($fhandle,filesize($fname));)

Then I'm stuck, since I need the content of $txt back in my JS, either
in a global JS variable or as the value in a <textarea>, whatever.
I tried the cookie mechanism, writing $txt as an escaped string in a
cookie in the PHP snipplet, then reading that cookie back in JS and
unescape it. That worked fine, but...

It works with short text files, it doesn't with longer ones. Obviously
there is a size limit to a cookie (4K as I remember).

So my question is, does anybody know how to tackle this one? It can't
be done by a cookie, it can't be done, as far as I can see, by the
$_GET. Since that one only communicates from HTML to PHP, not the other
way round, as far as I could find out (and yes, I Googled *alot* on

I don't need an extensive answer, just a magic hint. I can find the
tutorials and code it myself. Thanx in advance!


Re: Is there a reverse $_GET?

El 8 Mar 2006 22:44:54 -0800
VHfc escribió:

Quoted text here. Click to load it

well, and why don't you just output inside a textarea?, something like

echo "<textarea>$txt</textarea>";

if you don't want to see it you can just hide it using css

you can also use a hidden field for this:

echo "<input type=\"hidden\" id=\"txt_var\" value=\"$txt\"/>";

but i suppose a textarea is more aproppiate for what you want.

that's supposing I understand your problem, because I'm not too sure I
understood it

Juan José Gutiérrez de Quevedo
Director Técnico (
942544036 - 637447953

Re: Is there a reverse $_GET?

Just a quick correction to "Juan José Gutiérrez de Quevedo Pérez"'s
When you want to output values into html, always use htmlspecialchars.
For example, if $text is '<!--', then this will be evaluated as
<textarea><!--</textarea> ... The same problmem would be with using "
inside html tags. So really, for text area always use html specialchars
to show the actual output that user would like to edit. This will be
sent to the server as normal text (in your html, you have &gt; but when
osted you will receive >. So be quiet careful.
echo "<textarea>".htmlspecialchars($text)."</textarea>"; etc..

Re: Is there a reverse $_GET?

Juan José GutiérrezPérez schreef:

Quoted text here. Click to load it

Yes, I want it in a textarea. My problem was so "obvious" I didn't see
the woods by all the trees. Actually this must be the Murphy of posting
since I found a workable solution in the mean time by the
XMLHttpRequest object. It works great!
(in Dutch but the code is self-explaining)

Your solution is even simpler. But the advantage of the XMLHttpRequest
object is that I can reuse it for different types of request just by
the *.php?requesttype parameter.

Quoted text here. Click to load it

It was! Thanks for your reply.

@Drakazz: yes I'm quite aware of the character problem. I had it with
my cookie mechanism. I escape/unescape the string:
JS: result_dds = unescape(unescape(readMyCookie('comm_result_dds')));
PHP: stripslashes and rawurl

Thanx for your reply too!


Re: Is there a reverse $_GET?

There are compatibility problems with AJAX between IE and firefox and
with older browsers. Just echo-ing the content to the client is the
most portable method. For example I have noscript installed so your
site will not work at all for me if it relies on AJAX for critical

As more and more users become annoyed by abusive/intrusive javascripts,
more and more of them will use noscript or similar functions to disable
scripts and other objects. Javascript should be used for helper
functions like setting input focus on a form input element on page
load, submitting a form when the user presses enter in a textarea,
validating a form on the client side (perhaps assisted by AJAX), or
even for navigation menus. But in all these cases, the site should
still work fine with scripts disabled.


Re: Is there a reverse $_GET?

Quoted text here. Click to load it

This is the sort of technique I use too, where I have to use PHP to get  
data I need from a mysql database, but then manipulate it in JavaScript  
before using PHP to write it back to mysql.

The values I get from mysql are written into a form with hidden  
variables, and their values then picked up with an onload function to be  
put into JS variables. The new values are then later loaded into hidden  
form variables, and picked up by the next page as PHP values in order to  
be written back to the database.

-- tim

Site Timeline