[Javascript] JavaScript to PHP variable transfer

John Warner john at jwarner.com
Fri Aug 22 03:52:25 CDT 2003


When you stop to consider the requirement, the situation is impossible.
The Client has a value that the Server needs to know, but a channel of
communications from the Client to the Server is not allowed to exist.
This isn't a Javascript to PHP issue, this is a Client to Server issue.
I've no idea how you make the server aware of a value on the client if
the client is not allowed to pass that value along whether for bandwidth
issues or security. A channel of communication will have to be openned,
until that issue is resolved, the rest of this is moot. Either Post, Get
or Cookie is going to have to be allowed, these are the only channels
available(Head is a Coookie isn't it?). The customer in David's case
will have to be made to understand this reality.

John Warner
mailto:john at jwarner.com

> -----Original Message-----
> From: javascript-bounces at LaTech.edu 
> [mailto:javascript-bounces at LaTech.edu] On Behalf Of Roger Roelofs
> Sent: Friday, August 22, 2003 1:02 AM
> To: [JavaScript List]
> Subject: Re: [Javascript] JavaScript to PHP variable transfer
> 
> 
> Dave,
> 
> Sorry, I'm still confused.  The only way I know of, based on the http 
> protocol, for javascript to send data to a php script is via a GET or 
> POST, ( or I suppose a HEAD ) which may or may not contain a cookie.
> 
> 
> 
> 
> On Thursday, Aug 21, 2003, at 16:37 America/Detroit, David Lovering 
> wrote:
> 
> > Actually, you are quite close to the mark --
> >
> > Most of the present client/server communication is done by 
> way of the 
> > embedded IFRAME constructs which contain PHP scripts
> Technically they contain the 'output' of a php script.  
> Anyway, why not 
> have a hidden form on your main page with 1 hidden field.  Fill that 
> field with the data you want and submit it.  In the case of 
> creating or 
> changing php session variables (or database records), the field 
> contents could look like
> 	s2StateCode:MI
> 	s31CityName:Detroit
> 	....
> 
> Then have the form post to a generic php script that parses the field 
> like so
> <?php
> 	session_register();
> 	$aData = split($_POST['data'], "\n");  // this is off 
> the top of my 
> head, not tested.
> 	for ( $i = 0; $i < length($data); $i++ ) {
> 		$thisVar = split($aData[$i], ":");
> 		$_SESSION[$thisVar[0]] = $thisVar[1];
> 	}
> ?>
> 
> Obviously, real life is more complicated than that sample code, but I 
> hope it gives you food for thought.
> 
> >  Considering that POST, GET,
> > PUT, and cookies are all vigorously disabled,
> If that is true, the server can't be properly called a http (web) 
> server at all. It couldn't even handle simple page requests.
> 
> > The real problem is not getting PHP to talk to JavaScript (that is
> > easy!),
> > but rather the reverse.  Short
> > of using JavaScript to "invoke" a piece of PHP script as 
> per the "src="
> > destination inside a frame, ...
> 
> The only other options I can think of, have already been 
> mentioned i.e. 
> java with sockets and xml, and in fact most web services protocols 
> layer on top of http, so GET and/or POST are required there as well.
> 
> I feel like I'm not correctly understanding your situation, because I 
> feel like I'm telling you stuff you already know.  A sample of what 
> you're trying to do would be most useful.  Not real data, or even the 
> real forms, just a page with the same kinds of elements and 
> interactions would help me brainstorm.  If you don't have a public 
> server for this, I could host some test pages for you.
> 
> 
> Roger,
> 
> Roger Roelofs
> Datacomp Appraisal Services
> 
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu 
> https://lists.LaTech.edu/mailman/listinfo/javascript
> 



More information about the Javascript mailing list