468,315 Members | 1,415 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,315 developers. It's quick & easy.

Is there a reverse $_GET?

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
it).

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

VHfc

Mar 9 '06 #1
5 1378
El 8 Mar 2006 22:44:54 -0800
VHfc escribió:
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...


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 (ju****@iteisa.com)
ITEISA (http://www.iteisa.com)
942544036 - 637447953
Mar 9 '06 #2
Just a quick correction to "Juan José Gutiérrez de Quevedo Pérez"'s
post:
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..

Mar 9 '06 #3
Juan José GutiérrezPérez schreef:
echo "<input type=\"hidden\" id=\"txt_var\" value=\"$txt\"/>";
but i suppose a textarea is more aproppiate for what you want.
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!

http://www.sitemasters.be/?pagina=tu...&id=433#object
(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.
that's supposing I understand your problem, because I'm not too sure I
understood 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!

VHfc

Mar 9 '06 #4
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
content.

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.

-Robert

Mar 9 '06 #5
In article <20****************************@iteisa.com>,
Juan José Gutiérrez de Quevedo Pérez <ju****@iteisa.com> wrote:
El 8 Mar 2006 22:44:54 -0800
VHfc escribió:
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...


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\"/>";


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
Mar 9 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Thomas Carcaud | last post: by
2 posts views Thread by carramba | last post: by
7 posts views Thread by Dan | last post: by
32 posts views Thread by Nuno Paquete | last post: by
27 posts views Thread by meltedown | last post: by
2 posts views Thread by Georg Weiler | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.