Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #14892 > unrolled thread

Newby neds help

Started byF. George McDuffee <gmcduffee@mcduffee-associates.us>
First post2015-02-07 14:38 -0600
Last post2015-02-09 20:02 -0500
Articles 13 on this page of 33 — 8 participants

Back to article view | Back to comp.lang.php


Contents

  Newby neds help F. George McDuffee <gmcduffee@mcduffee-associates.us> - 2015-02-07 14:38 -0600
    Re: Newby neds help Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-02-07 16:31 -0500
    Re: Newby neds help "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-02-07 23:30 +0100
    Re: Newby neds help Tim Streater <timstreater@greenbee.net> - 2015-02-07 22:36 +0000
    Re: Newby neds help Denis McMahon <denismfmcmahon@gmail.com> - 2015-02-08 00:06 +0000
      Re: Newby neds help "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-02-08 01:29 +0100
        Re: Newby neds help Jerry Stuckle <jstucklex@attglobal.net> - 2015-02-07 20:22 -0500
          Re: Newby neds help "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-02-08 02:33 +0100
            Re: Newby neds help Jerry Stuckle <jstucklex@attglobal.net> - 2015-02-07 20:54 -0500
        Re: Newby neds help Denis McMahon <denismfmcmahon@gmail.com> - 2015-02-08 13:27 +0000
          Re: Newby neds help "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-02-08 15:22 +0100
            Re: Newby neds help Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-02-08 21:58 +0100
              Re: Newby neds help "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-02-08 22:56 +0100
                Re: Newby neds help Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-02-08 23:36 +0100
                  Re: Newby neds help "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-02-09 00:14 +0100
                    Re: Newby neds help Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-02-09 00:42 +0100
                      Re: Newby neds help "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-02-09 00:58 +0100
                  Re: Newby neds help Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-02-09 00:30 +0100
                    Re: Newby neds help "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-02-10 00:53 +0100
            Re: Newby neds help Denis McMahon <denismfmcmahon@gmail.com> - 2015-02-08 21:46 +0000
              Re: Newby neds help "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-02-09 00:40 +0100
                Re: Newby neds help Denis McMahon <denismfmcmahon@gmail.com> - 2015-02-09 19:34 +0000
                  HTTP (was: Newby neds help) "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-02-10 02:04 +0100
          Re: Newby neds help F. George McDuffee <gmcduffee@mcduffee-associates.us> - 2015-02-08 20:06 -0600
            Re: Newby neds help Matthew Carter <m@ahungry.com> - 2015-02-08 21:55 -0500
              Re: Newby neds help F. George McDuffee <gmcduffee@mcduffee-associates.us> - 2015-02-09 00:13 -0600
            Re: Newby neds help Tim Streater <timstreater@greenbee.net> - 2015-02-09 09:46 +0000
            Re: Newby neds help "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-02-10 01:14 +0100
      Re: Newby needs help F. George McDuffee <gmcduffee@mcduffee-associates.us> - 2015-02-07 19:29 -0600
        Re: Newby needs help "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-02-08 02:40 +0100
        Re: Newby needs help Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-02-07 21:36 -0500
    Re: Newby neds help Jerry Stuckle <jstucklex@attglobal.net> - 2015-02-07 21:33 -0500
    Re: Newby neds help Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-02-09 20:02 -0500

Page 2 of 2 — ← Prev page 1 [2]


#14920

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2015-02-09 00:40 +0100
Message-ID<mb8s5j$4q9$1@solani.org>
In reply to#14914
Denis McMahon wrote:

> On Sun, 08 Feb 2015 15:22:29 +0100, Christoph M. Becker wrote:
> 
>> No, of course there is no such rule.  It would not make much sense, for
>> example, to submit data of a search form via a POST request.  On the
>> other hand, the data for a survey which are going to be stored on the
>> server (what is what the OP wants to accomplish), should not be
>> submitted via a GET request.
> 
> That's your opinion of course, based on your personal interpretation of 
> various documents.

I'm mostly basing my statement on RFC 7231, not on various documents.

Regarding my statement that it would not make much sense to submit data
of a search form via a POST request, Thomas 'PointedEars' Lahn has
already made some constructive critism elsewhere in this thread, and
shown that this statement is wrong in the *general* case.

> In so far as http and server side scripting is concerned, it matters very 
> little to either the browser or the web server whether data is 
> transferred using the get or post methods, subject to any technical 
> limitations relevant to the chosen request method. 

However, submitting data that are going to be stored on the server
(appended to a file) with a GET request, would obviously be a violation
of RFC 7231:

| Of the request methods defined by this specification, the GET, HEAD,
| OPTIONS, and TRACE methods are defined to be safe.

| Request methods are considered "safe" if their defined semantics are
| essentially read-only; [...]

| A request method is considered "idempotent" if the intended effect on
| the server of multiple identical requests with that method is the
| same as the effect for a single such request. Of the request methods
| defined by this specification, PUT, DELETE, and safe request methods
| are idempotent.

> I am sure 
> however that the OP will consider your unsolicited opinion on the matter 
> with whatever gravity[1] he feels it deserves.
> 
> [1] gravity - the force that transfers poop from my butt to the toilet.

I presume that the OP won't fall prey to your miserable appeal to
emotion, but rather is open to reasoning based on facts.

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#14929

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2015-02-09 19:34 +0000
Message-ID<mbb24l$a4b$3@dont-email.me>
In reply to#14920
On Mon, 09 Feb 2015 00:40:37 +0100, Christoph M. Becker wrote:

> I'm mostly basing my statement on RFC 7231, not on various documents.

> However, submitting data that are going to be stored on the server
> (appended to a file) with a GET request, would obviously be a violation
> of RFC 7231:

As far as I can tell, RFC 7231 specifies a data transfer protocol. It's 
outside the remit or concern of such a protocol what happens to any data 
it carries after it has been transferred.

That you can't spot this flaw in the document you're quoting speaks 
volumes for your knowledge of the internet.

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#14933 — HTTP (was: Newby neds help)

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2015-02-10 02:04 +0100
SubjectHTTP (was: Newby neds help)
Message-ID<mbble7$alq$1@solani.org>
In reply to#14929
Denis McMahon wrote:

> On Mon, 09 Feb 2015 00:40:37 +0100, Christoph M. Becker wrote:
> 
>> I'm mostly basing my statement on RFC 7231, not on various documents.
> 
>> However, submitting data that are going to be stored on the server
>> (appended to a file) with a GET request, would obviously be a violation
>> of RFC 7231:
> 
> As far as I can tell, RFC 7231 specifies a data transfer protocol. It's 
> outside the remit or concern of such a protocol what happens to any data 
> it carries after it has been transferred.

At least that's not the case for HTTP, which specifies, for instance,
the semantics of (client-side) caching.  If that was not so, the *WWW*
would be an even greater mess as it is.

Consider the given survey form would be submitted via a GET request.
Anybody requesting the very URI again, would cause the same record to be
appended to the file another time.  This could even be the original
submitter, pressing F5 inadvertently -- a former POST submission would
have triggered a warning in any contemporary browser.[1]  Furthermore
the original submitter might bookmark the current URI after form
submission -- consider what happens when she accesses the bookmark next
time.[2]  Consider what happens if this URI is shared on a social
network, for instance.

> That you can't spot this flaw in the document you're quoting speaks 
> volumes for your knowledge of the internet.

Ex falso quodlibet.

[1] I am aware that multiple submission of the same data are still
possible with a POST request without warning, though.
[2] I am also aware that there are workarounds to prevent storing the
data twice, but these are unreliable and merely try to work around the
HTTP specification.

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#14924

FromF. George McDuffee <gmcduffee@mcduffee-associates.us>
Date2015-02-08 20:06 -0600
Message-ID<q3ufdap97pu4skagckk3dc2bn21f3hcn05@4ax.com>
In reply to#14907
On Sun, 8 Feb 2015 13:27:54 +0000 (UTC), Denis McMahon
<denismfmcmahon@gmail.com> wrote:

>On Sun, 08 Feb 2015 01:29:17 +0100, Christoph M. Becker wrote:
>
>> Denis McMahon wrote:
>
>>> Then use php to read the submitted user data from the $_POST or $_GET
>>> array (depending which form method you use) and process it into your
>>> survey, using appropriate data validation and verification.
>
>> It seems to be noteworthy that the form method should not be subject to
>> an arbitrary choice of the developer, but rather should comply to RFC
>> 7231 section 4[1].  Therefore a GET request would be inappropriate,
>> denis.
>
>A POST request may indeed be more appropriate than a GET request, that is 
>a decision for the developer to make. However, there is no rule that 
>states "form data must only be transferred to the server using POST".
>
>Up to the OP to choose the mechanism that best suits his data.
=======================

NB:  I use 16 point font in my ng reader because of a vision
problem, and this may cause "funky" line breaks in the code
snippits.

Thanks to everyone for their helpful comments and
suggestions!

We seem to be making  asymptotic progress to a solution to
my undoubtedly stupid problem.

I agree that the POST function is the most appropriate.
There is no need to cache the url or bookmark it.

My problem is I can't get the flaming POST function/command
to work no matter what I try.

the visitor counter works fine 
<snip>
	<span class="auto-style35">You are visitor # <script
src="http://mcduffee-associates.us/PHP/hitctr/counter.php?page=dummy"></script>
</span></td>
</snip>
and MDItab.php [for Major Depression Inventory  + tab
delimited] to append the data to a file is located is
located in the same directory.

Please show me *EXACTLY* what the client side POST should
look like to send window.upstring which is the concatenated
tab delimited data string to MDItab.php  *AND*

*EXACTLY* what the function in MDItab.php should be to
receive the data string and assign it to a variable.  

My last effort was:

<?php
// Work In Progress !!!!!!!!!!!!!!!!!!!
// cut and paste from web
// 21 June 14 GmcD
// how called in HTML: <script
src="http://mcduffee-associates.us/PHP/MDI/MDItab.php?MDIstring=window.upload"></script>
// ?? no quotes because I want variable contents, not
variable name window.upload
// <script src= MyURLstring></script> 
$MDIstring = $_GET[MDIstring]  
{{{{Q: should MDIstring in sq brackets be window.upstring?
I tried this and no workee}}}}
print('got to MDItab.php' );
// Did data string load??
if ( ! isset($_GET['MDIstring']) )  // quotes?
{
	die('ERROR: 'PROBLEMS WITH UpYouGo/MDItab.php');
} // end data xfer check
</snip>

If I can get the data across, I can take it from there.

This is where my problem is. No combination or permutation
of the examples on the web or in several "dummy's guides"
has worked.  I need something more than a black box with the
notation, "here the magic happens."

also tried this --  NO WORKEE
<snip>
//
// directly writes to file.
$handle =
fopen('http://www.mcduffee-associates.us/post/mdi/mdidta.tsv',
'ab');
// 'ab' is append binary, may need to change to 'at' for
/cr/lf xlation
// int fwrite( resource $handle , string $string [, int
$length ] )
intval fwrite( resource $handle,  string $window.upload )
// bool fclose ( resource $handle )
 boll fclose( resource $handle )
 //
</snip>

Unka' George


 




-- 
Unka' George

"Gold is the money of kings, 
silver is the money of gentlemen, 
barter is the money of peasants, 
but debt is the money of slaves"
 
-Norm Franz, "Money and Wealth in the New Millenium" 

[toc] | [prev] | [next] | [standalone]


#14926

FromMatthew Carter <m@ahungry.com>
Date2015-02-08 21:55 -0500
Message-ID<874mqvbxoz.fsf@ahungry.com>
In reply to#14924
F. George McDuffee <gmcduffee@mcduffee-associates.us> writes:

> On Sun, 8 Feb 2015 13:27:54 +0000 (UTC), Denis McMahon
> <denismfmcmahon@gmail.com> wrote:
>
>>On Sun, 08 Feb 2015 01:29:17 +0100, Christoph M. Becker wrote:
>>
>>> Denis McMahon wrote:
>>
>>>> Then use php to read the submitted user data from the $_POST or $_GET
>>>> array (depending which form method you use) and process it into your
>>>> survey, using appropriate data validation and verification.
>>
>>> It seems to be noteworthy that the form method should not be subject to
>>> an arbitrary choice of the developer, but rather should comply to RFC
>>> 7231 section 4[1].  Therefore a GET request would be inappropriate,
>>> denis.
>>
>>A POST request may indeed be more appropriate than a GET request, that is 
>>a decision for the developer to make. However, there is no rule that 
>>states "form data must only be transferred to the server using POST".
>>
>>Up to the OP to choose the mechanism that best suits his data.
> =======================
>
> NB:  I use 16 point font in my ng reader because of a vision
> problem, and this may cause "funky" line breaks in the code
> snippits.
>
> Thanks to everyone for their helpful comments and
> suggestions!
>
> We seem to be making  asymptotic progress to a solution to
> my undoubtedly stupid problem.
>
> I agree that the POST function is the most appropriate.
> There is no need to cache the url or bookmark it.
>
> My problem is I can't get the flaming POST function/command
> to work no matter what I try.
>
> the visitor counter works fine 
> <snip>
> 	<span class="auto-style35">You are visitor # <script
> src="http://mcduffee-associates.us/PHP/hitctr/counter.php?page=dummy"></script>
> </span></td>
> </snip>
> and MDItab.php [for Major Depression Inventory  + tab
> delimited] to append the data to a file is located is
> located in the same directory.
>
> Please show me *EXACTLY* what the client side POST should
> look like to send window.upstring which is the concatenated
> tab delimited data string to MDItab.php  *AND*
>
> *EXACTLY* what the function in MDItab.php should be to
> receive the data string and assign it to a variable.  
>
> My last effort was:
>
> <?php
> // Work In Progress !!!!!!!!!!!!!!!!!!!
> // cut and paste from web
> // 21 June 14 GmcD
> // how called in HTML: <script
> src="http://mcduffee-associates.us/PHP/MDI/MDItab.php?MDIstring=window.upload"></script>
> // ?? no quotes because I want variable contents, not
> variable name window.upload
> // <script src= MyURLstring></script> 
> $MDIstring = $_GET[MDIstring]  
> {{{{Q: should MDIstring in sq brackets be window.upstring?
> I tried this and no workee}}}}
> print('got to MDItab.php' );
> // Did data string load??
> if ( ! isset($_GET['MDIstring']) )  // quotes?
> {
> 	die('ERROR: 'PROBLEMS WITH UpYouGo/MDItab.php');
> } // end data xfer check
> </snip>
>
> If I can get the data across, I can take it from there.
>
> This is where my problem is. No combination or permutation
> of the examples on the web or in several "dummy's guides"
> has worked.  I need something more than a black box with the
> notation, "here the magic happens."
>
> also tried this --  NO WORKEE
> <snip>
> //
> // directly writes to file.
> $handle =
> fopen('http://www.mcduffee-associates.us/post/mdi/mdidta.tsv',
> 'ab');
> // 'ab' is append binary, may need to change to 'at' for
> /cr/lf xlation
> // int fwrite( resource $handle , string $string [, int
> $length ] )
> intval fwrite( resource $handle,  string $window.upload )
> // bool fclose ( resource $handle )
>  boll fclose( resource $handle )
>  //
> </snip>
>
> Unka' George

Don't fopen() an URL, use the filesystem's file path.

For your javascript, get firefox + firebug for a much easier time
debugging what is going on (or an equivalent such as Chromium's built in
inspector), as you can enter a javascript statement at a time in the REPL.

-- 
Matthew Carter (m@ahungry.com)
http://ahungry.com

[toc] | [prev] | [next] | [standalone]


#14927

FromF. George McDuffee <gmcduffee@mcduffee-associates.us>
Date2015-02-09 00:13 -0600
Message-ID<b7hgda5gmt9uq37mbf9ome68tatsvkc5op@4ax.com>
In reply to#14926
On Sun, 08 Feb 2015 21:55:40 -0500, Matthew Carter
<m@ahungry.com> wrote:

>For your javascript, get firefox + firebug for a much easier time
>debugging what is going on (or an equivalent such as Chromium's built in
>inspector), as you can enter a javascript statement at a time in the REPL.

javascript + HTML is working fine on both Firefox and
Exploder (albeit page was far harder to create than with
Front Page, which if this was still running on the server I
would have had this project done in a few hours including
the data up/download).  

 I have a version of the php program [not posted] that works
in that it creates/opens a text file on the server and
decodes/appends dummy data strings that I manually load
in-line to a string array and then into the write string
variable, so it should work if I can get the flaming POST
interface operating.  

Some graphics still need to be uploaded to be displayed on
the server version but page is fully functional [try it out]
except........  for my inability to one way or another
jam/ram/cram <window.upstring> into MDItab.php on the
server.  If this was on the shop floor, I would be reaching
for a bigger hammer or possibly a Rotorooter.   

At this point I am not looking for an elegant solution, JUST
A KLUGE TO CRAM THE DATA STRING INTO THE PHP PROGRAM TO
WRITE TO A FILE ON THE SERVER. 

Firefox is my main browser and I have firebug installed, but
for WYSIWYG page layout I find that M/S Expression Web 4 is
what I use most of the time.  [FWIW: Bought it just before
M/S released it for free...]   I find this to be a good code
editor for both JS/HTML and php, and is a good IDE for me. 

Now if I can just get that web survey to talk to the
server!!!!!!!!!!!!!!!!!!! 

Unka' George


-- 
Unka' George

"Gold is the money of kings, 
silver is the money of gentlemen, 
barter is the money of peasants, 
but debt is the money of slaves"
 
-Norm Franz, "Money and Wealth in the New Millenium" 

[toc] | [prev] | [next] | [standalone]


#14928

FromTim Streater <timstreater@greenbee.net>
Date2015-02-09 09:46 +0000
Message-ID<090220150946382044%timstreater@greenbee.net>
In reply to#14924
In article <q3ufdap97pu4skagckk3dc2bn21f3hcn05@4ax.com>, F. George
McDuffee <gmcduffee@mcduffee-associates.us> wrote:

>if ( ! isset($_GET['MDIstring']) )  // quotes?

It's safer to use quotes, as it says in the documentation.

-- 
"... you must remember that if you're trying to propagate a creed of 
 poverty, gentleness and tolerance,  you need a very rich, powerful,
 authoritarian organisation to do it."             - Vice-Pope Eric

[toc] | [prev] | [next] | [standalone]


#14931

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2015-02-10 01:14 +0100
Message-ID<mbbihq$iu$1@solani.org>
In reply to#14924
F. George McDuffee wrote:

> Please show me *EXACTLY* what the client side POST should
> look like to send window.upstring which is the concatenated
> tab delimited data string to MDItab.php  *AND*
> 
> *EXACTLY* what the function in MDItab.php should be to
> receive the data string and assign it to a variable.

You shouldn't expect ready to use solutions from this newsgroup, but
rather some helpful (and sometimes maybe not so helpful) hints. :)

The following code is hardly analyzable, due to line breaks inserted by
newsreaders.  You should consider reformatting any code to not exceed,
say, 72 characters per line, before posting it to Usenet.

> <?php
> // Work In Progress !!!!!!!!!!!!!!!!!!!
> // cut and paste from web
> // 21 June 14 GmcD
> // how called in HTML: <script
> src="http://mcduffee-associates.us/PHP/MDI/MDItab.php?MDIstring=window.upload"></script>
> // ?? no quotes because I want variable contents, not
> variable name window.upload
> // <script src= MyURLstring></script> 
> $MDIstring = $_GET[MDIstring]  

Here the trailing semicolon is missing.  It doesn't have to be written
on the same line, though, but that's customary and easier to read.  The
missing semicolon causes the PHP engine to abort script processing with
a fatal error.  I suggest you enable error_reporting and have a look in
the error log.[1]

> if ( ! isset($_GET['MDIstring']) )  // quotes?

Yes.  You should always quote strings (opposed to constants).

[1] <http://php.net/manual/en/errorfunc.configuration.php>

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#14899 — Re: Newby needs help

FromF. George McDuffee <gmcduffee@mcduffee-associates.us>
Date2015-02-07 19:29 -0600
SubjectRe: Newby needs help
Message-ID<vrbddadeu9o0glpnngov3456lht0gn4ulp@4ax.com>
In reply to#14896
Thanks to everyone who is responding.

>On Sat, 07 Feb 2015 14:38:22 -0600, F. George McDuffee wrote:
>
>> General problem for group: I can't get a tab delimited formatted string
>> to transfer from a client side web survey
>
>Sounds like you're trying to reinvent the wheel but not sure how to do it.
Indeed!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! This was a piece of
cake when Front Page was working.
>
>Trying to implement your own method of data transfer (eg tab delimited 
>formatted string which you then need to parse on the server) to pass data 
>from the client to the server when html and the http protocol already 
>have built in methods to handle the data transfer and php provides a 
>mechanism for easy access to the string data is a waste of time and 
>effort.
Don't want to invent anything, just use $_POST or $_GET to
communicate with PHP.  Tab delimited strings used because it
is easy to import data in this format into excel. Server
does no processing other than converting URL safe string
back to standard ascii and appending (or creating) tab
delimited flat ascii file, thus no need to parse.  
>
>Assuming your "client side web survey" uses typical html input elements, 
>select / option lists and textareas etc, you don't need any javascript at 
>all to prepare the data for the transmission to the server, you can just 
>wrap the user input up in a form and use the html / http features to 
>transfer the data fields to your server.

Javascript needed to score the survey and display message to
user based on that total score. Survey is "live" [feel free
to try it] but accumulates no data. 2  Alert()s used to
display the tab delimited and URL safe strings
[window.upstring=encodeURIComponent(window.upstring)] the
program generates from the user inputs. This part seems to
be working fine
 http://mcduffee-associates.us/MDI05g.html

>
>Then use php to read the submitted user data from the $_POST or $_GET 
>array (depending which form method you use) and process it into your 
>survey, using appropriate data validation and verification.
My problem is I can't get either post or get to do anything.
Because of the possibility of user entering significant
amounts of text would like to use $_POST  If you try program
it displays the tab delimited and URICencoded strings ok and
tries to post from the error message.  I can't seem to get
around this transfer problem.

Don't want/need to do any processing on the server.  Just
want to convert window.upstring string back to standard tab
delimited ascii using string urldecode(string $str)
http://tinyurl.com/luls3u and accumulate data in tab
delimited flat ascii file by appending to end of existing
file to be FTP downloaded and imported into excel for local
processing/analysis.  

How/why did this get so complicated???????????????


Unka' George


-- 
Unka' George

"Gold is the money of kings, 
silver is the money of gentlemen, 
barter is the money of peasants, 
but debt is the money of slaves"
 
-Norm Franz, "Money and Wealth in the New Millenium" 

[toc] | [prev] | [next] | [standalone]


#14901 — Re: Newby needs help

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2015-02-08 02:40 +0100
SubjectRe: Newby needs help
Message-ID<mb6ept$82h$1@solani.org>
In reply to#14899
F. George McDuffee wrote:

> How/why did this get so complicated???????????????

Because you're trying to reinvent the wheel.

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#14904 — Re: Newby needs help

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2015-02-07 21:36 -0500
SubjectRe: Newby needs help
Message-ID<EYzBw.469426$Sn4.120243@fx10.iad>
In reply to#14899
On Saturday February 7 2015 20:29, in comp.lang.php, "F. George McDuffee"
<gmcduffee@mcduffee-associates.us> wrote:

> Thanks to everyone who is responding.

You're welcome.

[snip]

> Don't want to invent anything, just use $_POST or $_GET to
> communicate with PHP.

To me, the best choice would be to have the Javascript POST the data, and
the PHP to read it from the appropriate $_POST variable.

Reasons: If the Javascript uses GET, it will have to concatenate the
variable name and the data to the URL before performing the GET. This has a
couple of consequences:
 1) you must take extra steps in the Javascript to create the proper URL
    before you open the PHP page
 2) your data is not secure, as it is now plaintext, included as part of the
    request URL and can be intercepted, read, and/or forged 

If the Javascript uses POST, then the data does not have to be urlencoded or
concatenated to the URL before the Javascript open() call, and the data is
not exposed as part of the URL, and is now less susceptable to forgery.
However, the Javascript must write the data as part of the document it is
posting, using the appropriate transfer semantics (characterset, type,
name, content).

In both cases, your PHP has to know where to look for the data. It must use
$_GET[] if you had the Javascript open the page with the GET mode, or use
the $_POST[] if you had the Javascript open the page with the POST mode.

[snip]

> How/why did this get so complicated???????????????

Using Javascript to transfer data is more complicated than using html
webforms, that's for certain.


-- 
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request

[toc] | [prev] | [next] | [standalone]


#14903

FromJerry Stuckle <jstucklex@attglobal.net>
Date2015-02-07 21:33 -0500
Message-ID<mb6ht6$b5r$1@dont-email.me>
In reply to#14892
On 2/7/2015 3:38 PM, F. George McDuffee wrote:
> About me: Nyme Unka_George. I am a long time lurker on this
> group and a retired academic with some obsolete web design
> experience [Front Page].  I am attempting to learn HTML5,
> Javascrip, and PHP at the same time, and have made some
> progress [got a cut and paste hit-counter working].
> 
> General problem for group: I can't get a tab delimited
> formatted string to transfer from a client side web survey
> which uses Javascript to score a survey [which is working
> see  http://mcduffee-associates.us/MDI05g.html ] to a server
> side PHP program which will append the tab delimited
> formatted string to an existing tab delimited file [which is
> also working, using inline dummy data.  The PHP program is
> shown below.  PHP is running locally on XAMPP v3.2.1  
> 
> Background: Survey is from the World Health Organization and
> measures depression.  The survey has been validated across a
> number of cultures.  My interest is in determining the
> extent and degree of depression in rural/micro urban areas
> as part of RED [Rural Economic Development] effort, and by
> doing multiple regression analysis of the depression and
> demographic data determine how much, if any, correlation
> exists job status, housing, living arrangements, length of
> commute, job tenure, type of housing, etc.  This is
> important because depression, both “overt” which this survey
> attempts to measure, and “masked” depression have been shown
> to closely associated with “learned helplessness,” [subject
> of another survey in preparation] which if prevalent will
> prevent a community growth/development even when
> opportunities are available.  Therefore this must be
> corrected, either before, or concurrent with, any economic
> development efforts if these are to succeed.  My web RED web
> page, along with some earlier versions on the survey in
> Visual Basic can be seen at
> http://mcduffee-associates.us/RED/redmain.htm   
> 
> what I think is the important part of the Javscript program
> is
<snip>

First of all, forget Christoph M. Becker's comments.  He's just a troll,
only capable of (mis)quoting standards and trolling.

As for your problem - there are several ways of doing this.  Personally,
I would just POST the form to the server and have the PHP code create
the tab-delimited string.  Even better would be to use fputcsv() to
write the string to a .csv file.

You can get what you have here to work, but it's going to take a bit of
debugging.  Your first step should be to separate your attempt into two
separate pieces.

You didn't post all of the javascript (which would be off-topic here,
anyway), but my suggestion would be to get that piece working first.
Lew already gave you some good comments on problems in your javascript
code; you should be able to get more help on that part from
comp.lang.javascript.

As for debugging - create a PHP page which simply saves the data it gets
to a file - nothing more.  Now strip your javascript to the absolute
minimum required (i.e. send one field, unformateed), and get that
working.  Now add additional code, one piece at a time, and get it working.

Alternatively, use a javascript debugger such as Firebug on Firefox to
debug your javascript and get it to send the proper information.

Once you have the javascript working, start adding code to your PHP file
to do what you need.

Also, think about your code.  What do you actually need?  For instance,
is the IP address really important?  If not, leave it out.  You can
always add code later when you get it working.

Also - normally for a PHP development system (you DO have a development
system separate from your production system, right), I normally
recommend your php.ini file contains:

error_reporting = E_ALL
display_errors = On

However, this doesn't help when you're using AJAX because errors in
handling an AJAX request aren't displayed.  So for this reason I also
recommend you have

log_errors = On
error_log = (full path to a file here)

BTW - it's easy to change the wrong php.ini file.  To find the one being
used, just create a file with only the following line:

<?php phpinfo(); ?>

Upload it to the root directory of your web server and load it in your
browser.  One of the things it will show is the php.ini file being used.

As for an alternative (and easier) implementation - just put all of your
input fields in a form and POST it to the server.  No javascript
required on the client side (unless you wish to validate data before it
is sent).

Now on the server side, your PHP gets all of the data from the $_POST
array and builds a tab-delimited string and writes the string to a file
(an even better way, IMHO, would be to build an array of parameters and
use fputcsv() to write as a .csv file).  Much more straightforward and
easier to implement.

But whichever way you go, I can't stress enough - validate EVERY piece
of information coming from the client.  This means data type and value
for each item, to ensure it is good.  Never trust anything from the client.

I know this is kinda long - but I hope it helps some.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#14932

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2015-02-09 20:02 -0500
Message-ID<OMcCw.38682$1t1.21891@fx09.iad>
In reply to#14892
On Saturday February 7 2015 15:38, in comp.lang.php, "F. George McDuffee"
<gmcduffee@mcduffee-associates.us> wrote:
[snip]

Using the code you gave us, your Javascript should look something like...

  function SendString( )
  {
    xmlhttp.open("POST","MDItest.php",true);

    // window.upstring contains "MDIstring=<your tab delimited data>"
    xmlhttp.send(window.upstring);
  }

and your PHP should look like...

  <?php

    if (isset($_POST['MDIstring']))
    {
      // append received MDIstring to file of saved MDIstrings
      $handle = fopen($FILEPATH,'a');
      fwrite($handle,$_POST['MDIstring']);
      fclose($handle);
    }

  ?>
  
The client javascript POSTs the survey values; the server PHP script
retrieves the survey values from the POST variables.

Enhancements (like urlencoding, etc) are left to you.

Good luck
-- 
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.php


csiph-web