Discussion:
Newby needs help
(too old to reply)
F. George McDuffee
2015-02-07 20:28:20 UTC
Permalink
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
***************************
function SendString( ){
// function to move client datastring to server for
appending to file
// set to local server test file -- will require
real file and refactoring
// MDItest.php not set to reveive data yet.
alert("got to start of SendString( )");
xmlhttp.open("POST","MDItest.php",true);
xmlhttp.send(window.upstring);
// no xmlhttp.close( );
alert("got through open/send of
SendString( )");
}
***************************

a fragment of how the the tab delimited string is
constructed
********************
Qloc = document.getElementById("textarea1");
// Qval = Qloc.options[Qloc].innerHTML;
Qval =
document.getElementById("textarea1").value;
window.upstring = window.upstring + '\t"' + Qval
+ '"';
Qloc = document.getElementById("input1");
Qval = document.getElementById("input1").value;
window.upstring = window.upstring + '\t"' + Qval
+ '"';
// append local time
window.upstring = window.upstring +'\t"' + t + '"';
//
// append client browser information
var NavResult = "test";
NavResult = navigator.userAgent.substr(0,60);
// alert(NavResult);
window.upstring = window.upstring + "\t\"" +
NavResult + "\"";
************************




PHP program to append survey data to existing file server
file
***********************************
<?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]
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

flush( );
ob_flush( );

// show string on client browser
print(MDIstring);
// decode $MDIstring and restore special characters
$MDIstring = urldecode($MDIstring); // may be unnecessary as
get is used
print(MDIstring);
flush( );
ob_flush( );




AppendMDILine($MDIstring);

function AppendMDILine($MDIstring) {
// alternate file to append form data
// string is tab delimited quoted form data string
// append client IP
// add client IP and newline
// \t = tab ; \n = new line line feed ; \r = carriage
return
// add ip temp commented out add quote + cr/lf
$MDIstring = $MDIstring +'\"\r\n'
// following line commented out for test
// $MDIstring = $MDIstring + '\t"' + get_client_ip( ) +
'"\r\n';
//
// directly writes to file.
// need to create directories and check path
// $handle =
fopen('http://www.mcduffee-associates.us/post/mdi/mdidta.tsv',
'ab');
// commented out for test
$handle = fopen('www/web_surveys/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 ] )
fwrite( $handle, $MDIstring );
// bool fclose ( resource $handle )
fclose($handle);
} // end AppendMDILine()

//
//
// Function to get the client ip address
function get_client_ip() {
$ipaddress = '';
if (getenv('HTTP_CLIENT_IP'))
$ipaddress = getenv('HTTP_CLIENT_IP');
else if(getenv('HTTP_X_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
else if(getenv('HTTP_X_FORWARDED'))
$ipaddress = getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_FORWARDED_FOR');
else if(getenv('HTTP_FORWARDED'))
$ipaddress = getenv('HTTP_FORWARDED');
else if(getenv('REMOTE_ADDR'))
$ipaddress = getenv('REMOTE_ADDR');
else
$ipaddress = 'UNKNOWN';

return $ipaddress;
} // end get_client_ip()


?>
**********************

FWIW: The accumulated tab delimited data file will be
downloaded using FTP, and imported into Excel. I have a
very nice inexpensive multiple regression analysis add-in
called win-stat http://www.winstat.com/ , with which I am
familiar, and which produces publication quality graphs,
which can be output as a pdf file for easy web publication.
In the unlikely event the dataset gets too big for excel,
there is always R.

Thanks for your help. Any suggestions about the survey and
responses would be helpful.
--
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"
F. George McDuffee
2015-02-08 01:29:03 UTC
Permalink
Thanks to everyone who is responding.
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"
Christoph M. Becker
2015-02-08 01:40:13 UTC
Permalink
Post by F. George McDuffee
How/why did this get so complicated???????????????
Because you're trying to reinvent the wheel.
--
Christoph M. Becker
MASTER TROLL BAIT
2015-03-09 15:52:00 UTC
Permalink
Post by Christoph M. Becker
Post by F. George McDuffee
How/why did this get so complicated???????????????
Because you're trying to reinvent the wheel.
--
Christoph M. Becker
Sure like wheels don't ya, just go on and on about them. WHEEL LOVER!
http://christoph-m-becker.is-a-jerk.com/

Lew Pitcher
2015-02-08 02:36:19 UTC
Permalink
On Saturday February 7 2015 20:29, in comp.lang.php, "F. George McDuffee"
Post by F. George McDuffee
Thanks to everyone who is responding.
You're welcome.

[snip]
Post by F. George McDuffee
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]
Post by F. George McDuffee
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
mrr
2015-02-21 23:24:16 UTC
Permalink
Post by F. George McDuffee
Background: Survey is from the World Health Organization and
measures depression. The survey has been validated across a
Interesting.

But I wonder, an internet survey? Would that be a representative sample
of population?
And wouldn't a person under depression be less inclined to take the
decision to participate in it?

Maybe what's relevant wouldn't be the absolute result but more the
rural/urban difference in ratio!
--
mrr
Loading...