473,508 Members | 2,434 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1550
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2572
by: Thomas Carcaud | last post by:
I read php manual many times but I can't figure out register_globals works. I m using Php 4.3.2 and register_globals on. It seems to have different effects on $_GET and $_SESSION. First with $_GET...
2
3399
by: carramba | last post by:
Hi! Tahnx for taking time and reading! This script should load default page and default stylesheet, but its only loads default page, you have to actualy click on the style link to load style......
7
11858
by: Dan | last post by:
I was trying to troubleshoot a login page that doesn't work - it keeps saying the login/password is missing - when my tracing discovered this peculiar behavior. register_globals is off, so at...
32
32962
by: Nuno Paquete | last post by:
Hi group. I'm using this code to see if is there any parameter for variable "menu": if($_GET == "downloads") .... But this code log errors if there is no parameter passed (this heappens at...
4
1675
by: MAS | last post by:
I want to do what devasp.com has done. They offer their directory via a single-line javascript include. See: http://www.devasp.com/directory.asp You can drop this code onto any web page and...
27
5290
by: meltedown | last post by:
urlencode turns # into %23 When I sent it thru $_GET, it dissapears, along with anything that comes after it. for example: urlencode turns HOYDM_EXC_#4_NAT into HOYDM_EXC_%234_NAT When I...
2
8944
by: Georg Weiler | last post by:
Hi, I'm biting my nails on this for several days now, hope that someone of you can help me...: On my page, the user can display tables, created out of a database. So I have several <a href>...
2
3106
by: keeps21 | last post by:
I have a script that recieves an id number via the address bar when a link is clicked. ie . index.php?id=1 if the link was for the story whose ID is 1. My script checks if a user is logged in,...
8
5665
by: printline | last post by:
Hello I have a problem which i hope someone can help me with. I have a website where customers can login and their current and previous orders. What i need now is for the customers to look...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7118
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.